﻿var buy_order = {
    //结算页相关ajax的url
    URL: {
        province: function () {
            return global_ajaxdomain + 'getprovince.jhtm?t=' + new Date().getTime();
        },
        cities: function () {
            return global_ajaxdomain + 'getcities.jhtm?t=' + new Date().getTime();
        },
        counties: function () {
            return global_ajaxdomain + 'getcounties.jhtm?t=' + new Date().getTime();
        },
        villages: function () {
            return global_ajaxdomain + 'getvillages.jhtm?t=' + new Date().getTime();
        },
        zip: function () {
            return global_ajaxdomain + 'getzip.jhtm?t=' + new Date().getTime();
        },
        addconsignee: function () {
            return global_ajaxdomain + 'consignee/addconsignee.jhtm?t=' + new Date().getTime();
        },
        updateconsignee: function () {
            return global_ajaxdomain + 'consignee/updateconsignee.jhtm?t=' + new Date().getTime();
        },
        deleteconsignee: function () {
            return global_ajaxdomain + 'consignee/deleteconsignee.jhtm?t=' + new Date().getTime();
        },
        getCheckOutData: function () {
            return global_ajaxdomain + 'getCheckOutData.jhtm?t=' + new Date().getTime();
        },
        usevirtualcurrency: function () {
            return global_ajaxdomain + 'usevirtualcurrency.jhtm?t=' + new Date().getTime();
        },
        datarecovery: function () {
            return global_ajaxdomain + "checkRecoveryService.jhtm?t=" + new Date().getTime();
        },
        updateMoreCheckOutCache: function () {
            return global_ajaxdomain + 'updateMoreCheckOutCache.jhtm?t=' + new Date().getTime();
        },
        updateCheckOutCache: function () {
            return global_ajaxdomain + 'updateCheckOutCache.jhtm?t=' + new Date().getTime();
        },
        submitOrder: function () {
            return global_ajaxdomain + 'submitOrder.jhtm?t=' + new Date().getTime();
        },
        getcart: function () {
            return global_ajaxdomain + 'getcart.jhtm?terminal=' + terminal + '&t=' + new Date().getTime();
        },
        checkServiceSNCode: function () {
            return global_ajaxdomain + "checkSNCode.jhtm?t=" +  new Date().getTime();
        }
    }
};
var products_c = null;
//修改ie 下 trim 不支持的bug
String.prototype.trim = function () {
    return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
var shareConsigneeId = null;
var shareInvoiceAddressId = "";
var shareContractAddressId = "";
var invoiceFaid = "";
var iso2o = false;
var couponidArr = [];
var couponidTempArr = [];
/*定义结算缓存更新项“枚举”*/
if (typeof UpdateBackFillItem == "undefined") {
    var UpdateBackFillItem = {};
    UpdateBackFillItem.DELIVER = 1;//更新地址
    UpdateBackFillItem.INVOICE = 2;//发票
    UpdateBackFillItem.PAYTYPE = 3;//支付方式
    UpdateBackFillItem.CMANNAGER_CODE = 4;//客服经理编码
    UpdateBackFillItem.ORDER_REMARK = 5;//订单备注
    UpdateBackFillItem.COUPONIDS = 6;//优惠券
    UpdateBackFillItem.COUPONCODE = 7;//优惠码
    UpdateBackFillItem.INNERBUYMONEY = 8;//内购
    UpdateBackFillItem.GIFTCARES = 9;//礼品卡
    UpdateBackFillItem.HAPPYBEAN = 10;//乐豆
    UpdateBackFillItem.SN = 11;//SN码
    UpdateBackFillItem.IDENTITY_ID = 12;//身份信息验证ID
    UpdateBackFillItem.DATARECOVERY = 14;//数据恢复险
    UpdateBackFillItem.INVOICEADDRESS = 15;//收票地址
    UpdateBackFillItem.INVOICEISCONSIGNEE = 16;//收票地址是否同收货地址
    UpdateBackFillItem.CONTRACTADDRESS = 17;//合同地址
    UpdateBackFillItem.CONTRACTISCONSIGNEE = 18;//合同地址是否同收货地址
    UpdateBackFillItem.ISSENDCONTRACT = 19;//是否寄送合同
}
/*address enum*/
if (typeof AddressTypeEnums == 'undefined') {
    var AddressTypeEnums = {};
    AddressTypeEnums.DONGDE = "dongde";//懂得收货地址
    AddressTypeEnums.SH = "SH";//收货地址
    AddressTypeEnums.SP = "SP";//收票地址
    AddressTypeEnums.HT = "HT";//合同地址
}
function showAdd(addresstype) {

    $("#bg-" + addresstype).css({
        display: "block", height: $(document).height()
    });
    var $box = $('.box-' + addresstype);
    var $showbtn = $('.showbtn-' + addresstype);
    $box.css({
        //设置弹出层距离左边的位置
        "left": ($("body").width() - $box.width()) / 2 + "px",
        //设置弹出层距离上面的位置
        "top": ($(".showbtn-" + addresstype).offset().top + $showbtn.height()) + 10 + "px",
        display: "block"
    });
    //新增默认选中
    $("#isCheck-" + addresstype).attr("checked", 'true');
    //$("#isCheck").removeAttr("checked");
    $.ajax({
        type: "get",
        url: buy_order.URL.province(),
        async: false,
        dataType: "json",
        success: function (data) {
            if (data != null) {
                if (data.provinces != null) {

                    for (var i = 0; i < data.provinces.split(',').length; i++) {
                        var option = "<option >" + data.provinces.split(',')[i] + "</option>";
                        $("#goodsProvince-" + addresstype).append(option);
                    }
                }
            }
        }
    });
}

function closeAlert(addresstype) {
    $("#bg-" + addresstype + ",.box-" + addresstype).css("display", "none");
    $("#flag1-" + addresstype).val("0");
    $("#name-" + addresstype).val("");
    $("#mobile-" + addresstype).val("");
    $("#goodsStreet-" + addresstype).val("");
    $("#postcode-" + addresstype).val("");
    $("#mail-" + addresstype).val("");
    $("#isCheck-" + addresstype).attr("checked", "true");
    $("#goodsProvince-" + addresstype).find("option").remove();
    $("#goodsProvince-" + addresstype).append('<option value="">省份</option>');
    $("#goodsCity-" + addresstype).find("option").remove();
    $("#goodsCity-" + addresstype).append('<option value="">城市</option>');
    $("#goodsCounty-" + addresstype).find("option").remove();
    $("#goodsCounty-" + addresstype).append('<option value="">区/县</option>');
    $("#phone-" + addresstype).val("");
    $("#zip-" + addresstype).val("");
    $("#goodsVillage-" + addresstype).find("option").remove();
    $("#goodsVillage-" + addresstype).append('<option value="">乡镇</option>');
    $("#company-" + addresstype).val("");
    $("#submitbtn-" + addresstype).attr("disabled", false).html("保存收货人信息");
}

function getCities(addresstype) {
    var province = $("#goodsProvince-" + addresstype).find("option:selected").text();
    if (province != "") {
        $.ajax({
            type: "get",
            url: buy_order.URL.cities(),
            async: false,
            data: {provincename: encodeURIComponent(province, "utf-8")},
            dataType: "json",
            success: function (data) {
                if (data != null) {
                    if (data.cities != null) {
                        $("#goodsCity-" + addresstype).find("option").remove();
                        var option = "<option>城市</option>";
                        $("#goodsCity-" + addresstype).append(option);
                        $("#goodsCounty-" + addresstype).find("option").remove();
                        option = "<option>区/县</option>";
                        $("#goodsCounty-" + addresstype).append(option);
                        $("#goodsVillage-" + addresstype).find("option").remove();
                        option = "<option>乡镇</option>";
                        $("#goodsVillage-" + addresstype).append(option);
                        for (var i = 0; i < data.cities.split(',').length; i++) {
                            option = "<option>" + data.cities.split(',')[i] + "</option>";
                            $("#goodsCity-" + addresstype).append(option);
                        }
                    }
                }
            }
        });
    }
}

function getCounties(addresstype) {

    var city = $("#goodsCity-" + addresstype).find("option:selected").text();
    var province = $("#goodsProvince-" + addresstype).find("option:selected").text();
    if (city != "") {
        $.ajax({
            type: "get",
            url: buy_order.URL.counties(),
            async: false,
            data: {provincename: encodeURIComponent(province, "utf-8"), cityname: encodeURIComponent(city, "utf-8")},
            dataType: "json",
            success: function (data) {
                if (data != null) {
                    if (data.counties != null) {
                        $("#goodsCounty-" + addresstype).find("option").remove();
                        var option = "<option>区/县</option>";
                        $("#goodsCounty-" + addresstype).append(option);
                        $("#goodsVillage-" + addresstype).find("option").remove();
                        option = "<option>乡镇</option>";
                        $("#goodsVillage-" + addresstype).append(option);
                        for (var i = 0; i < data.counties.split(',').length; i++) {
                            var option = "<option>" + data.counties.split(',')[i] + "</option>";
                            $("#goodsCounty-" + addresstype).append(option);
                        }
                    }
                }
            }
        });
        if (shopId == 8 || shopId == 9) {
            getZip(province, city, addresstype)
        }
    }

}
/*get smb zip */
function getZip(province, city, addresstype) {

    if (city != "") {
        $.ajax({
            type: "get",
            url: buy_order.URL.zip(),
            async: false,
            data: {provincename: encodeURIComponent(province, "utf-8"), cityname: encodeURIComponent(city, "utf-8")},
            dataType: "json",
            success: function (data) {
                if (data != null) {
                    if (data.zip != null) {
                        $("#zip-" + addresstype).val(data.zip);
                    }
                }
            }
        });
    }
}
function getVillages(addresstype) {

    var province = $("#goodsProvince-" + addresstype).find("option:selected").text();
    var city = $("#goodsCity-" + addresstype).find("option:selected").text();
    var county = $("#goodsCounty-" + addresstype).find("option:selected").text();
    if (county != "") {
        $.ajax({
            type: "get",
            url: buy_order.URL.villages(),
            async: false,
            data: {
                provincename: encodeURIComponent(province, "utf-8"),
                cityname: encodeURIComponent(city, "utf-8"),
                countryname: encodeURIComponent(county, "utf-8")
            },
            dataType: "json",
            success: function (data) {
                if (data != null) {
                    if (data.district != null) {
                        $("#goodsVillage-" + addresstype).find("option").remove();
                        var option = "<option>乡镇</option>";
                        $("#goodsVillage-" + addresstype).append(option);
                        for (var i = 0; i < data.district.split(',').length; i++) {
                            var option = "<option>" + data.district.split(',')[i] + "</option>";
                            $("#goodsVillage-" + addresstype).append(option);
                        }
                    }
                }
            }
        });
    }
}
function getStringLengthForChinese(val) {
    var str = new String(val);
    var bytesCount = 0;
    for (var i = 0, n = str.length; i < n; i++) {
        var c = str.charCodeAt(i);
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
            bytesCount += 1;
        } else {
            bytesCount += 2;
        }
    }
    return bytesCount;
}
//保存收货地址
function submitInfo(addresstype) {
    var temp_value = null;
    var type_name = "";
    /*default sh address*/
    if (addresstype == AddressTypeEnums.DONGDE) {
        var goodsProvince = $("#s_province").find("option:selected").text();
        var goodsCity = $("#s_city").find("option:selected").text();
        var goodsCounty = $("#s_county").find("option:selected").text();
        //编码
        var s_province = $("#s_province").find("option:selected").val();
        var s_city = $("#s_city").find("option:selected").val();
        var s_county = $("#s_county").find("option:selected").val();
    } else {
        var goodsProvince = $("#goodsProvince-" + addresstype).find("option:selected").text();
        var goodsCity = $("#goodsCity-" + addresstype).find("option:selected").text();
        var goodsCounty = $("#goodsCounty-" + addresstype).find("option:selected").text();
        var goodsVillage = $("#goodsVillage-" + addresstype).find("option:selected").text();

    }

    temp_value = $("#name-" + addresstype).val();
    if (isEmpty(temp_value)) {
        alert('请输入收货人姓名');
        return false;
    }
    if (getStringLengthForChinese(temp_value) > 20) {
        alert('收货人姓名超过20字符');
        return false;
    }
    if (!is_forbid(temp_value)) {
        alert('收货人姓名含有非法字符');
        return false;
    }

    /*  var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
     if (containSpecial.test($("#name-" + addresstype).val().trim())) {
     alert('请输入正确' + type_name + '人姓名');
     return false;
     }
     */
    temp_value = $("#company-" + addresstype).val();
    if (temp_value != undefined && isEmpty(temp_value)) {
        alert("请您填写收货公司");
        return false;
    }
    if (temp_value != undefined && !is_forbid(temp_value)) {
        alert("收货公司含有非法字符");
        return false;
    }

    var phone = $("#phone-" + addresstype).val();
    var mobile = $("#mobile-" + addresstype).val();
    if (isEmpty(mobile)) {
        alert('请您填写收货人手机号码');
        return false;
    }

    if (!isEmpty(mobile)) {
        var reg = /^1[3-9]\d{9}$/;
        if (!reg.test(mobile)) {
            alert('请输入正确的手机号码');
            return false;
        }
    }
    if (!isEmpty(phone)) {
        if (!is_forbid_new(phone)) {
            alert('固定电话号码中含有非法字符');
            return false;
        }
        if (!checkPhoneNew(mobile, phone)) {
            alert('请输入正确的固定电话，格式为:XXX(区号)-XXXXXXXX(电话号码)-XXX(分机号)');
            return false;
        }
    }
    if (goodsProvince == "省份" || goodsCity == "城市" || goodsCounty == "区/县") {
        alert("请选择正确的省份/城市/区县");
        return false;
    }
    if ((shopId == 8 || shopId == 9) && goodsVillage == "乡镇") {
        alert("请选择正确的乡镇");
        return false;
    }
    temp_value = $("#goodsStreet-" + addresstype).val();
    if (isEmpty(temp_value)) {
        alert("请您填写详细地址");
        return false;
    }
    if (!is_forbid(temp_value)) {
        alert("详细地址中含有非法字符");
        return false;
    }
    if (temp_value.length > 250) {
        alert("详细地址过长");
        return false;
    }
    temp_value = $("#zip-" + addresstype).val();
    if (temp_value != undefined) {
        if (isEmpty(temp_value)) {
            alert("请您填写邮政编码");
            return false;
        } else if (!isNumber(temp_value) || $.trim(temp_value).length != 6) {
            alert("请您填写正确的邮政编码");
            return false;
        }
    }


    temp_value = $("#mail-" + addresstype).val();
    if (temp_value != "" && !temp_value.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
        alert("邮箱格式不正确");
        return false;
    }

    if (temp_value.length > 100) {
        alert("邮箱长度不能大于100位");
        return false;
    }
    $("#submitbtn-" + addresstype).attr("disabled", true).html("正在提交...");
    var name = $.trim($("#name-" + addresstype).val());
    var mobile = $.trim($("#mobile-" + addresstype).val());
    var goodsStreet = $.trim($("#goodsStreet-" + addresstype).val());
    var mail = $.trim($("#mail-" + addresstype).val());
    var flag = $.trim($("#flag1-" + addresstype).val());
    var deliverid = $.trim($("#deliveridupdate-" + addresstype).val());
    var isdefault = $("#isCheck-" + addresstype).is(':checked') ? 1 : 0;
    var zip = $.trim($("#zip-" + addresstype).val());
    var company = $.trim($("#company-" + addresstype).val());
    /*Default shipping address*/
    var ajaxdata = {
        delivername: CtoH(name),
        deliverprovice: goodsProvince,
        delivercity: goodsCity,
        delivercounty: goodsCounty,
        deliverStreet: CtoH(goodsStreet),
        delivertele: CtoH(phone),
        delivermobile: CtoH(mobile),
        deliveremail: CtoH(mail),
        isDefault: isdefault,
        deliverid: deliverid,
        zip: CtoH(zip),
        type: addresstype

    };
    if (addresstype == AddressTypeEnums.DONGDE) {
        ajaxdata.areaNos = s_province + "|" + s_city + "|" + s_county;
    } else {
        ajaxdata.company = CtoH(company);
        ajaxdata.towerShip = goodsVillage;
    }
    $.ajax({
        type: "post",
        url: flag == 1 ? buy_order.URL.updateconsignee() : buy_order.URL.addconsignee(),
        async: false,
        data: ajaxdata,
        dataType: "json",
        success: function (data) {
            $("#submitbtn-" + addresstype).attr("disabled", false).html("保存收货人信息");
            if (data != null) {
                if (data.rc != null && data.rc == "0") {
                    if (isdefault == 0) {
                        updateCheckOutCacheAddress(addresstype, "A");
                    } else {
                        if (flag == 1) {
                            updateCheckOutCacheAddress(addresstype, "A" + deliverid);
                        } else {
                            updateCheckOutCacheAddress(addresstype, "A" + data.data);
                        }
                    }
                } else {
                    closeAlert();
                    showMessage(3000, "系统繁忙，请稍后再试！");
                    // showMessage(3000, data.msg);
                }
            }
        },
        error: function () {
            $("#submitbtn-" + addresstype).attr("disabled", false).html("保存收货人信息");
        }
    });

}
/*update cache by addresstype */
function updateCheckOutCacheAddress(addresstype, content) {
    var updateItem;
    if (addresstype == AddressTypeEnums.DONGDE || addresstype == AddressTypeEnums.SH) {
        updateItem = UpdateBackFillItem.DELIVER;
    } else if (addresstype == AddressTypeEnums.SP) {
        updateItem = UpdateBackFillItem.INVOICEADDRESS;
    } else if (addresstype == AddressTypeEnums.HT) {
        updateItem = UpdateBackFillItem.CONTRACTADDRESS;
    }
    updateCheckOutCache(updateItem, content);
}

$(function () {
    $(".showbtna").click(function () {
        // $(".box").hide();
        $("#bg").css({
            display: "block", height: $(document).height()
        });
        var $boxa = $('.boxa');
        var $showbtna = $('.showbtna');
        $boxa.css({
            //设置弹出层距离左边的位置
            "left": ($("body").width() - $boxa.width()) / 2 + "px",
            //设置弹出层距离上面的位置
            "top": ($showbtna.offset().top + $showbtna.height()) + 10 + "px",
            display: "block"
        });

        var head = $("#invoice_header").val();
        var type = $("#invoice_type").html();
        var data = {};
        if (head == "1") {
            $("#Radioheadtype2").prop("checked", "true");
            $("#invoiceheadcontent").attr("placeholder", "公司抬头");
            $("#tempinvoiceType_p").hide();
            $("#tempinvoiceType_c").show();
            if (type == "增值发票") {
                $("#12").prop("checked", "true");
                showZZInvoice();
            } else {
                $("#11").prop("checked", "true");
                var invoice_head = $("#invoice_head").html();
                canEdit();
                $("#invoiceheadcontent").val(invoice_head);
            }
        }
        if (head == "0") {
            $("#Radioheadtype1").prop("checked", "true");
            $("#invoiceheadcontent").attr("placeholder", "个人");
            $("#tempinvoiceType_c").hide();
            $("#tempinvoiceType_p").show();
            var invoice_head = $("#invoice_head").html();
            if (type == "普通发票") {
                $("#01").prop("checked", "true");
                canEdit();
            } else {
                $("#00").prop("checked", "true");
                canEdit();
            }
            $("#invoiceheadcontent").val(invoice_head);
        }
    });
    //点击关闭按钮的时候，遮罩层关闭
    $(".close").click(function () {
        $("#fapinfoid").css("display", "none")
        $("#bg,.boxa").css("display", "none");
    });

    //CTO
    $('.box_xq h2').bind('mouseenter', function () {
        $(this).siblings('ul').slideDown(300);
    });
    $('.box_xq').bind('mouseleave', function () {
        $(this).find('ul').slideUp(300);
    });

});


$(function () {
    $('.menuTitle').click(function () {
        if ($(this).siblings('.menuContent').css('display') == 'none') {
            $(this).siblings('.menuContent').css('display', 'block');
            $(this).find('a').addClass('add');
        } else {
            $(this).siblings('.menuContent').css('display', 'none');
            $(this).find('a').removeClass('add');
        }
    });


});


$(function () {
    navTopDown();
})

function navTopDown() {
    $('.ns_top_title').bind('mouseenter', function () {
        $(this).siblings('ul').slideDown(300);
        $(this).find('a').removeClass('ns_top_down').addClass('ns_top_up');
    });
    $('.ns_top_link').bind('mouseleave', function () {
        $(this).find('ul').slideUp(300);
        $(this).find('.ns_top_title').find('a').removeClass('ns_top_up').addClass('ns_top_down');
    })
}

//tab切换
function aCheck1() {
    document.getElementById("tab_01").style.display = "block";
    document.getElementById("tab_02").style.display = "none";
}
function bCheck2() {
    document.getElementById("tab_01").style.display = "none";
    document.getElementById("tab_02").style.display = "block";
}

$(function () {
    $('.hong').click(function () {
        $('.hong').removeClass('aa');
        $(this).addClass('aa');
    });
})

//切换支付方式
function choosePay(i) {
    $("#bgdiv" + i).addClass("pink").siblings().removeClass("pink");
    updatePayType();//更新支付方式的缓存
}

function chooseAddress(i, addresstype) {
    $("#chooseid-" + addresstype).val(i);
    $(".address-" + addresstype).removeClass("pink");
    $("#bgdiv" + i).addClass("pink");
    updateAddressCache(i, addresstype);
}

function getPayWay() {
    var boxArr = $("#box-b").find(".box-ax");
    var paytype = "0";
    for (var i = 0; i < boxArr.length; i++) {
        if ($("#box-b").find(".box-ax").eq(i).hasClass("pink")) {
            paytype = $("#box-b").find("div.box-ax")[i].id.substring(5);
        }
    }
    return paytype;
}
function getChoseId(addresstype) {
    return $("#chooseid-" + addresstype).val();
}

function deleteAddress_(deliverid, addresstype) {
    opencover("删除操作", "确认删除吗？", "deleteAddress('" + deliverid + "','" + addresstype + "')");
    //JS停止冒泡
    window.event ? window.event.cancelBubble = true : e.stopPropagation();
}

function deleteAddress(deliverid, addresstype) {

    var ajaxdata = {deliverid: deliverid, type: addresstype};
    $.ajax({
        type: "post",
        url: buy_order.URL.deleteconsignee(),
        async: false,
        data: ajaxdata,
        dataType: "json",
        success: function (data) {
            if (data != null) {
                if (data.rc == 0) {
                    closecover();
                    updateCheckOutCacheAddress(addresstype, "D" + deliverid);
                }
            }
        }
    });
}

/*获取选中的礼品卡*/
function getCheckedCashCardNos() {
    var cashCardNos = "";
    var cashCardMoney = "0.00";
    //内购额度
    var isLimitMoney = $('#innerLimitMoney').val();
    var item = $('input[type="checkbox"][name="cashCardCheckbox"]:checked');
    $.each(item, function (i, element) {
        if (isLimitMoney != "" && null != isLimitMoney && 'undefined' != isLimitMoney) {
            showMessage(3000, "您已使用内购额度，礼品卡和内购额度不能同时使用！");
            return;
        }
        var str = $(element).val().split(',');
        for (var j = 0; j < 1; j++) {
            cashCardMoney = parseFloat(cashCardMoney) + parseFloat(str[1]);
            cashCardNos += str[0] + '@'; //，将value添加到变量s中
        }
    });
    var lastChar = "";
    if (cashCardNos == null || cashCardNos == 'undefined' || cashCardNos == "") {
        lastChar = "";
    } else {
        lastChar = cashCardNos.lastIndexOf('@');
    }
    if (lastChar > 0) {//去除多于的@
        cashCardNos.substring(0, cashCardNos.length - 1);
    }
    $('#cashCardNum').text(item.length);
    $('#cashCardMoney').text(cashCardMoney);
    return cashCardNos;
}

/*update address (Multiple)*/
function updateAddress(village, company, zip, deliverid, delivername, delivermobile, deliverprovice, delivercity, delivercounty, deliverStreet, mail, isDefault, delivertele, areaNos, addresstype) {

    $("#bg-" + addresstype).css({
        display: "block", height: $(document).height()
    });
    var $box = $('.box-' + addresstype);
    var $showbtn = $('.showbtn-' + addresstype);
    $box.css({
        //设置弹出层距离左边的位置
        "left": ($("body").width() - $box.width()) / 2 + "px",
        //设置弹出层距离上面的位置
        "top": ($showbtn.offset().top + $showbtn.height()) + 10 + "px",
        display: "block"
    });
    $("#flag1-" + addresstype).val("1");
    /*render  Area*/
    if (addresstype == AddressTypeEnums.SH || addresstype == AddressTypeEnums.SP || addresstype == AddressTypeEnums.HT) {
        renderArea(deliverprovice, delivercity, delivercounty, village, addresstype);
    } else if (addresstype == AddressTypeEnums.DONGDE) {
        if (!getCheckEmpty(areaNos)) {
            var anoArr = areaNos.split("|");
            $("#s_province").val(anoArr[0]);
            change(1);
            $("#s_city").val(anoArr[1]);
            change(2);
            $("#s_county").val(anoArr[2]);
        }
    }
    $("#deliveridupdate-" + addresstype).val(deliverid);
    $("#name-" + addresstype).val(delivername);
    $("#mobile-" + addresstype).val(delivermobile);
    $("#goodsStreet-" + addresstype).val(deliverStreet);
    if (getCheckEmpty(mail)) {
        $("#mail-" + addresstype).val("");
    } else {
        $("#mail-" + addresstype).val(mail);
    }
    if (getCheckEmpty(delivertele)) {
        $("#phone-" + addresstype).val("");
    } else {
        $("#phone-" + addresstype).val(delivertele);
    }

    if (isDefault == "1") {
        $("#isCheck-" + addresstype).prop("checked", "true");
    } else if (isDefault == "0") {
        $("#isCheck-" + addresstype).removeAttr("checked");
    }
    if ($("#zip-" + addresstype).val() != undefined) {
        $("#zip-" + addresstype).val(zip);
    }
    if ($("#company-" + addresstype).val() != undefined) {
        $("#company-" + addresstype).val(company);
    }
    //JS停止冒泡
    window.event ? window.event.cancelBubble = true : e.stopPropagation();
}
/*sh render provice city county*/
function renderArea(deliverprovice, delivercity, delivercounty, village, addresstype) {
    $.ajax({
        type: "get",
        url: buy_order.URL.province(),
        async: false,
        dataType: "json",
        success: function (data) {
            if (data != null) {
                if (data.provinces != null) {

                    for (var i = 0; i < data.provinces.split(',').length; i++) {
                        var option = "<option >" + data.provinces.split(',')[i] + "</option>";
                        $("#goodsProvince-" + addresstype).append(option);

                    }
                    var count = $("#goodsProvince-" + addresstype + " option").length;
                    for (var i = 0; i < count; i++) {
                        if ($("#goodsProvince-" + addresstype).get(0).options[i].text == deliverprovice) {
                            $("#goodsProvince-" + addresstype).get(0).options[i].selected = true;
                            break;
                        }
                    }
                    var province = $("#goodsProvince-" + addresstype).find("option:selected").text();
                    if (province != "") {
                        $.ajax({
                            type: "get",
                            url: buy_order.URL.cities(),
                            async: false,
                            data: {provincename: encodeURIComponent(province, "utf-8")},
                            dataType: "json",
                            success: function (data) {
                                if (data != null) {
                                    if (data.cities != null) {
                                        $("#goodsCity-" + addresstype).find("option").remove();
                                        for (var i = 0; i < data.cities.split(',').length; i++) {
                                            var option = "<option>" + data.cities.split(',')[i] + "</option>";
                                            $("#goodsCity-" + addresstype).append(option);
                                        }
                                    }
                                    count = $("#goodsCity-" + addresstype + " option").length;
                                    for (var i = 0; i < count; i++) {
                                        if ($("#goodsCity-" + addresstype).get(0).options[i].text == delivercity) {
                                            $("#goodsCity-" + addresstype).get(0).options[i].selected = true;
                                            break;
                                        }
                                    }
                                    var city = $("#goodsCity-" + addresstype).find("option:selected").text();
                                    if (city != "") {
                                        $.ajax({
                                            type: "get",
                                            url: buy_order.URL.counties(),
                                            async: false,
                                            data: {
                                                provincename: encodeURIComponent(province, "utf-8"),
                                                cityname: encodeURIComponent(city, "utf-8")
                                            },
                                            dataType: "json",
                                            success: function (data) {
                                                if (data != null) {
                                                    if (data.counties != null) {
                                                        $("#goodsCounty-" + addresstype).find("option").remove();
                                                        for (var i = 0; i < data.counties.split(',').length; i++) {
                                                            var option = "<option>" + data.counties.split(',')[i] + "</option>";
                                                            $("#goodsCounty-" + addresstype).append(option);
                                                        }
                                                        count = $("#goodsCounty-" + addresstype + " option").length;
                                                        for (var i = 0; i < count; i++) {
                                                            if ($("#goodsCounty-" + addresstype).get(0).options[i].text == delivercounty) {
                                                                $("#goodsCounty-" + addresstype).get(0).options[i].selected = true;
                                                                break;
                                                            }
                                                        }
                                                        if (shopId == 8 || shopId == 9) {
                                                            var county = $("#goodsCounty-" + addresstype).find("option:selected").text();
                                                            if (county != "") {
                                                                $.ajax({
                                                                    type: "get",
                                                                    url: buy_order.URL.villages(),
                                                                    async: false,
                                                                    data: {
                                                                        provincename: encodeURIComponent(province, "utf-8"),
                                                                        cityname: encodeURIComponent(city, "utf-8"),
                                                                        countryname: encodeURIComponent(county, "utf-8")
                                                                    },
                                                                    dataType: "json",
                                                                    success: function (data) {
                                                                        if (data != null) {
                                                                            if (data.district != null) {
                                                                                $("#goodsVillage-" + addresstype).find("option").remove();
                                                                                for (var i = 0; i < data.district.split(',').length; i++) {
                                                                                    var option = "<option>" + data.district.split(',')[i] + "</option>";
                                                                                    $("#goodsVillage-" + addresstype).append(option);
                                                                                }
                                                                                count = $("#goodsVillage-" + addresstype + " option").length;
                                                                                for (var i = 0; i < count; i++) {
                                                                                    if ($("#goodsVillage-" + addresstype).get(0).options[i].text == village) {
                                                                                        $("#goodsVillage-" + addresstype).get(0).options[i].selected = true;
                                                                                        break;
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                });
                                                            }
                                                        }

                                                    }
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                        });
                    }
                }
            }
        }
    });
}

/////////////////////////////////////////////////
//获取数据（渲染、展示）--开始
////////////////////////////////////////////////
/*
 * 获取结算页数据进行渲染（只有影响到价格的或者跳转页面的才能重新调用）
 * 1.url  ,链接域名
 * 2.terminal 终端
 */
function getcheckOutData(url, terminal) {
    $.post(buy_order.URL.getCheckOutData(url),
        {
            lid: lid,
            shopId: shopId,
            terminal: terminal
        }, function (data) {
            if (data.rc != 0) {
                /* if(data.rc != 20101){
                 showMessage(3000,data.msg);
                 }*/
                if (data.rc == 10014 || data.rc == 20101 || data.rc == 10010) {
                    window.location.href = buy_order.URL.getcart();
                } else {
                    showMessage(3000, data.msg);
                    $(".ui-mask").css("display", "none");
                    $(".purchase-loading").css("display", "none");
                }
                return;
            }
            var temp = data.data.checkOutOrder; //渲染
            var order = data.data.bfOrderVo;    //回显
            if (temp != null) {
                renderPage(temp, order, null);
            }
            $(".ui-mask").css("display", "none");
            $(".purchase-loading").css("display", "none");
        }, 'json');
}
/*
 * 获取结算页数据进行渲染（只有影响到价格的或者跳转页面的才能重新调用）
 * 1.url  ,链接域名
 * 2.terminal 终端
 */
function getcheckOutDataNew(url, terminal, updateItem) {
    $.post(buy_order.URL.getCheckOutData(url),
        {
            lid: lid,
            shopId: shopId,
            terminal: terminal
        }, function (data) {
            if (data.rc != 0) {
                cleanInput(updateItem, 2);//获取数据失败，附空缓存
                /*if(data.rc != 20101){
                 showMessage(3000,data.msg);
                 }*/
                if (data.rc == 10014 || data.rc == 20101 || data.rc == 10010) {
                    window.location.href = buy_order.URL.getcart();
                } else {
                    showMessage(3000, data.msg);
                }
                return;
            }
            var temp = data.data.checkOutOrder; //渲染
            var order = data.data.bfOrderVo;    //回显
            if (temp != null) {
                renderPage(temp, order, updateItem);
            }
        }, 'json');
}

//更新缓存并checkout
function usevirtualcurrency(updateItem, content) {
    var ajaxData;
    if (updateItem == UpdateBackFillItem.COUPONIDS) {
        var arr = [];
        for (var i = 0; i < couponidTempArr.length; i++) {
            if (content.indexOf(couponidTempArr[i]) != -1) {
                arr.push(couponidTempArr[i]);
            }
        }
        ajaxData = arr.join(",");
    } else {
        ajaxData = content;
    }

    $.post(buy_order.URL.usevirtualcurrency(), {
        lid: lid,
        shopId: shopId,
        terminal: terminal,
        virtualType: updateItem,
        content: ajaxData,
        ss: new Date().getTime()
    }, function (data) {
        if (data != null) {
            if (data.rc != 0) {
//                         if(updateItem==UpdateBackFillItem.COUPONIDS){
//                             $("#isSuccessful").val(0);
//                         }
                //showMessage(3000,data.msg);
                if (data.rc == 10014 || data.rc == 20101 || data.rc == 10010) {
                    window.location.href = buy_order.URL.getcart();
                } else {
                    showMessage(3000, data.msg);
                }
                cleanInput(updateItem, 1);
                if (updateItem == UpdateBackFillItem.COUPONIDS) {
                    // var selectedCoupon = $("#selectedCoupon").val();
                    var selectedCoupon = content.split(",").pop();
                    if (selectedCoupon) {
                        couponidArr.remove(selectedCoupon);
                        $("#" + selectedCoupon).removeClass("pinks");
                        $("#selectedCoupon").val("");
                        var count = 0;
                        var totalMoney = 0;
                        $("#tab_01 .bgses").each(function (i, n) {
                            var obj = $(n);
                            if (obj.hasClass("pinks")) {
                                var id = obj.attr("id");
                                count++;
                                var at = $("#" + id + " p").eq(0).html()
                                totalMoney += parseInt(at);
                            }
                        });
                        updateCouponids();
                        $("#sy").html(count);
                        $("#zj").html(totalMoney);
                    }
                }
                return;
            }
            var temp = data.data.checkOutOrder; //渲染
            var order = data.data.bfOrderVo;    //回显
            if (temp != null) {
                renderPage(temp, order, updateItem);
            }
        }
    }, 'json');
}

/*渲染地址*/
function showConsignList(data, order, addresstype) {
    var addHtml = '';
    var _this = $("#box-a");
    if (addresstype == AddressTypeEnums.DONGDE || addresstype == AddressTypeEnums.SH) {
        addHtml = '<p>收货信息：<span class="showbtn-' + addresstype + ' showbtn new_p" latag="latag_pc_ordersubmit_newaddress" onclick="showAdd(\'' + addresstype + '\')"><span  style="cursor:pointer;">＋新增收货地址</span></span></p><div id="addressList-' + addresstype + '">  <input type="hidden" id="chooseid-' + addresstype + '"> </div>';
        _this = $("#box-a");
    } else if (addresstype == AddressTypeEnums.SP) {
        var isAddress = '';
        if (shopId == 8) {
            isAddress = '<span><input type="checkbox" id="invoice-cb" onclick="invoiceIsConsignee()" />同收货地址</span>';
        }
        addHtml = '<p class="address—p line50">发票寄送信息：' + isAddress + '<span class="showbtn-' + addresstype + ' showbtn new_p" latag="latag_pc_ordersubmit_newaddress" onclick="showAdd(\'' + addresstype + '\')"><span style="cursor:pointer;">＋新增发票地址</span></span></p> <div id="addressList-' + addresstype + '"> <input type="hidden" id="chooseid-' + addresstype + '"></div> ';
        _this = $("#box-d");
    } else if (addresstype == AddressTypeEnums.HT) {
        addHtml = '<p class="address—p line50">合同寄送信息：<span><input type="checkbox" id="contract-send" onclick="isSendContract()"/>是否寄送合同</span></p><div class="line50" id="contract-is" style="display: none"><input style="margin-left:102px" type="checkbox" id="contract-cb" onclick="contractIsConsignee()"/>同收货地址</span><span class="showbtn-' + addresstype + ' showbtn new_p" latag="latag_pc_ordersubmit_newaddress" onclick="showAdd(\'' + addresstype + '\')"><span style="cursor:pointer;">＋新增合同地址</span></span><div id="addressList-' + addresstype + '"> <input type="hidden" id="chooseid-' + addresstype + '"></div></div> ';
        _this = $("#box-e");
    }
    _this.empty();
    _this.append(addHtml);
    var more_address = '<div class="address_div" onclick="showAddress(\'addressList-' + addresstype + '\')">' +
        '<a href="javascript:" class="more_address"><img src="' + pcCssHomeModule + '/images/update_down.jpg" class="update_ico" /><span class="update_address">更多地址</span></a>' +
        '</div>';
    if (data.length < 2) {
        $.each(data, function (i, item) {
            item.isdefault = "1";
            $("#addressList-" + addresstype).append(getAddressItem(item, addresstype, true));
            $("#addressList-" + addresstype).append(more_address);
        })
    } else {
        $.each(data, function (i, item) {
            if (i == 0) {
                $("#addressList-" + addresstype).append(getAddressItem(item, addresstype, true));
            } else if (i == 1) {
                $("#addressList-" + addresstype).append('<div class="update_item">' + getAddressItem(item, addresstype, false) + '</div>');
            } else {
                $("#addressList-" + addresstype).find(".update_item").append(getAddressItem(item, addresstype, false));
            }
        })
        $("#addressList-" + addresstype).append(more_address);
    }

    /*new address page*/
    _this.append(getNewAddressStr(addresstype));
    if (order) {
        $(".address-" + addresstype).removeClass("pink");
        $("#bgdiv" + order).addClass("pink");
        $("#chooseid-" + addresstype).val(order);

        if (!getCheckEmpty($("#addressList-" + addresstype + ">input").val()) && !getCheckEmpty($("#addressList-" + addresstype + ">div:first").attr("id")) && $("#addressList-" + addresstype + ">div:first").attr("id") != ("#bgdiv" + $("#addressList-" + addresstype + ">input").val())) {
            $("#addressList-" + addresstype + " .update_item>div:first").before($("#addressList-" + addresstype + ">div:first"));
            $("#addressList-" + addresstype + ">input").after($("#bgdiv" + $("#addressList-" + addresstype + ">input").val()));
        }
    }
}
function invoiceIsConsignee() {
    var ajaxdata = {
        lid: lid, shopId: shopId, terminal: terminal,
        cacheItems: [UpdateBackFillItem.INVOICEADDRESS, UpdateBackFillItem.INVOICEISCONSIGNEE],
        invoiceIsConsigneeId: "0",
        invoiceAddressId: "",
    }
    if ($("#invoice-cb").is(":checked")) {
        ajaxdata.invoiceIsConsigneeId = "1";
    } else {
        ajaxdata.invoiceIsConsigneeId = "0";
    }
    updateCheckOutCacheList(ajaxdata, AddressTypeEnums.SP);
}

function contractIsConsignee() {
    var ajaxdata = {
        lid: lid, shopId: shopId, terminal: terminal,
        cacheItems: [UpdateBackFillItem.CONTRACTADDRESS, UpdateBackFillItem.CONTRACTISCONSIGNEE, UpdateBackFillItem.ISSENDCONTRACT],
        contractIsConsigneeId: "0",
        contractAddressId: "",
        isSendContract: "1"
    }
    if ($("#contract-cb").is(":checked")) {
        ajaxdata.contractIsConsigneeId = "1";
    } else {
        ajaxdata.contractIsConsigneeId = "0";
    }
    updateCheckOutCacheList(ajaxdata, AddressTypeEnums.HT);
}
function isSendContract() {
    var ajaxdata = {
        lid: lid, shopId: shopId, terminal: terminal,
        cacheItems: [UpdateBackFillItem.CONTRACTADDRESS, UpdateBackFillItem.CONTRACTISCONSIGNEE, UpdateBackFillItem.ISSENDCONTRACT],
        contractIsConsigneeId: "0",
        contractAddressId: "",
        isSendContract: "1"
    }
    if ($("#contract-send").is(":checked")) {
        ajaxdata.isSendContract = "1";
    } else {
        ajaxdata.isSendContract = "0";
    }
    updateCheckOutCacheList(ajaxdata, AddressTypeEnums.HT);
}

function getAddressItem(item, addresstype, isDefault) {
    var areanos = addresstype == AddressTypeEnums.DONGDE ? item.areaNos : "";
    var townshipCode = getCheckEmpty(item.townshipCode) ? '' : item.townshipCode;
    var longAddress = item.provinceCode + item.cityCode + item.countyCode + item.address;
    if (addresstype == AddressTypeEnums.SH && (shopId == 8 || shopId == 9)) {
        longAddress = item.provinceCode + item.cityCode + item.countyCode + townshipCode + item.address;
    }
    if (longAddress.length > 25) {
        longAddress = longAddress.substring(0, 24) + "..."
    }
    var defaultSpan = '';
    var pink = '';
    if (item.isdefault == 1) {
        $("#chooseid-" + addresstype).val(item.id);
        defaultSpan = '<span>默认地址</span>';
        pink = 'pink';
    } else if (isDefault) {
        $("#chooseid-" + addresstype).val(item.id);
        pink = 'pink';
    }
    var telMobile = "";
    var phone = "";
    if (!getCheckEmpty(item.mobile)) {
        telMobile = hiddenMobile(item.mobile);

        phone = item.mobile;
    } else if (!getCheckEmpty(item.tel)) {
        telMobile = hiddenMobile(item.tel);
        //phone = item.tel;
    }
    return '<div class="box-ax bgse  address-' + addresstype + ' ' + pink + '"  id="bgdiv' + item.id + '" latag="latag_pc_ordersubmit_address" onclick="chooseAddress(\'' + item.id + '\',\'' + addresstype + '\')">' +
            '<input type="hidden" id="pre_phone" value="'+phone+'">'+
        '<p style="width:190px">' + item.name + '</p>' +
        '<p style="width:140px" id="pre_tel">' + telMobile + '</p>' +
        '<p style="width:500px">' + longAddress + '</p>' +
        '<p class="ax-sp">' + defaultSpan + '<span class="red showbtn" latag="latag_pc_ordersubmit_editaddress" onclick="updateAddress(\'' + item.townshipCode + '\',\'' + item.company + '\',\'' + item.zip + '\',\'' + item.id + '\',\'' + item.name + '\',\'' + item.mobile + '\',\'' + item.provinceCode + '\',\'' + item.cityCode + '\',\'' + item.countyCode + '\',\'' + item.address + '\',\'' + item.email + '\',\'' + item.isdefault + '\',\'' + item.tel + '\',\'' + areanos + '\',\'' + addresstype + '\')">修改</span><a href="javascript:void(0)" onclick="deleteAddress_(\'' + item.id + '\',\'' + addresstype + '\')">╳</a></p>' +
        '<img id="icon" src="' + pcCssHomeModule + '/images/pic-07.jpg' + '" id="icon"> </div>';

}

function showAddress(_this) {

    if (!getCheckEmpty($("#" + _this + ">input").val()) && !getCheckEmpty($("#" + _this + ">div:first").attr("id")) && $("#" + _this + ">div:first").attr("id") != ("#bgdiv" + $("#" + _this + ">input").val())) {
        $("#" + _this + " .update_item>div:first").before($("#" + _this + ">div:first"));
        $("#" + _this + ">input").after($("#bgdiv" + $("#" + _this + ">input").val()));
    }

    var ele = $(_this).parent().attr("id");
    if ($("#" + _this + ' .update_item').css("display") == "none") {
        $("#" + _this + ' .update_item').show();
        $("#" + _this + ' .update_ico').attr('src', pcCssHomeModule + '/images/update_up.jpg');
        $("#" + _this + ' .update_address').html('收起地址');
    } else {
        $("#" + _this + ' .update_item').hide();
        $("#" + _this + ' .update_ico').attr('src', pcCssHomeModule + '/images/update_down.jpg');
        $("#" + _this + ' .update_address').html('更多地址');
    }
}


/*new  address page*/
function getNewAddressStr(addresstype) {
    var zipStr = '<li>' +
        '<label><span>* </span>邮政编码：</label>' +
        '<input type="text"  id="zip-' + addresstype + '">' +
        '</li>';
    var companyStr = '';
    var mailPrompt = "用来接收订单提醒邮件，便于您及时了解订单状态";
    if (shopId == 8 || shopId == 9) {
        zipStr = '<li>' +
            '<label><span>* </span>邮政编码：</label>' +
            '<input type="text"  id="zip-' + addresstype + '" readonly>' +
            '</li>';
        companyStr = '<li>' +
            '<label><span>* </span>收货公司：</label>' +
            '<input type="text" id="company-' + addresstype + '">' +
            '</li>';
    }
    if (addresstype == AddressTypeEnums.SH) {
        var villageStr = '';
        if (shopId == 8 || shopId == 9) {
            villageStr = '<select id="goodsCounty-' + addresstype + '" name="goodsCounty-' + addresstype + '" onChange="getVillages(\'' + addresstype + '\')" style=" height:25px;width:120px">' +
                '<option value="">区/县</option>' +
                '</select>' +
                '<select id="goodsVillage-' + addresstype + '" name="goodsVillage-' + addresstype + '" style=" height:25px;width:120px">' +
                '<option value="">乡镇</option>' +
                '</select>';
            mailPrompt = "";
        } else {
            villageStr = '<select id="goodsCounty-' + addresstype + '" name="goodsCounty-' + addresstype + '"  style=" height:25px;width:120px">' +
                '<option value="">区/县</option>' +
                '</select>';
            zipStr = '';
        }
        return '<div id="bg-' + addresstype + '" class="bg-n"></div>' +
            '<div style="display:none" class="box-' + addresstype + ' box">' +
            '<input type="hidden" id="flag1-' + addresstype + '" value="0">' +
            '<input type="hidden" id="deliveridupdate-' + addresstype + '" value="">' +
            '<a class="close" href="javascript:void(0);" latag="latag_pc_ordersubmit_address_closealert" onclick="closeAlert(\'' + addresstype + '\')">╳</a>' +
            '<ul>' +
            '<li>' +
            '<label><span>* </span>收货人：</label>' +
            '<input type="text" id="name-' + addresstype + '" ><label id="alertName-' + addresstype + '" style="display:none;color:red">收货人不能为空</label>' +
            '</li>' + companyStr +
            '<li>' +
            '<label><span>* </span>手机：</label>' +
            '<input type="text" id="mobile-' + addresstype + '">' +
            '<label>  固定电话：</label>' +
            '<input type="text"  id="phone-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label><span>* </span>地址：</label>' +
            '<select id="goodsProvince-' + addresstype + '" name="goodsProvince-' + addresstype + '" onChange="getCities(\'' + addresstype + '\')" style=" height:25px;width:120px">' +
            '<option value="">省份</option>' +
            '</select>' +
            '<select id="goodsCity-' + addresstype + '" name="goodsCity-' + addresstype + '" onChange="getCounties(\'' + addresstype + '\')" style=" height:25px;width:120px">' +
            '<option value="">城市</option> ' +
            '</select>' + villageStr +
            '</li>' + zipStr +
            '<li>' +
            '<label><span>* </span>详细地址：</label>' +
            '<input type="text" style="width:410px;" id="goodsStreet-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label>邮箱：</label>' +
            '<input type="text" id="mail-' + addresstype + '">' +
            '<span style="color:red;vertical-align: middle;padding-left: 5px;">' + mailPrompt + '</span>' +
            '</li>' +
            '<li>' +
            '<label><input type="checkbox" style="width:14px;height:14px;margin-top: -8px;" id="isCheck-' + addresstype + '" latag="latag_pc_ordersubmit_address_defaultcheck">&nbsp;&nbsp;</label>' +
            '设置为默认收货地址' +
            '</li>' +
            '<li>' +
            '<label></label>' +
            '<button id="submitbtn-' + addresstype + '" onclick="submitInfo(\'' + addresstype + '\')" latag="latag_pc_ordersubmit_address_confirm">保存收货人信息</button>' +
            '</li>' +
            '</ul>' +
            '</div>';
    } else if (addresstype == AddressTypeEnums.SP) {
        return '<div id="bg-' + addresstype + '" class="bg-n"></div>' +
            '<div style="display:none" class="box-' + addresstype + ' box">' +
            '<input type="hidden" id="flag1-' + addresstype + '" value="0">' +
            '<input type="hidden" id="deliveridupdate-' + addresstype + '" value="">' +
            '<a class="close" href="javascript:void(0);" latag="latag_pc_ordersubmit_address_closealert" onclick="closeAlert(\'' + addresstype + '\')">╳</a>' +
            '<ul>' +
            '<li>' +
            '<label><span>* </span>收货人：</label>' +
            '<input type="text" id="name-' + addresstype + '" >' +
            '</li>' + companyStr +
            '<li>' +
            '<label><span>* </span>手机：</label>' +
            '<input type="text" id="mobile-' + addresstype + '">' +
            '<label>  固定电话：</label>' +
            '<input type="text"  id="phone-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label><span>* </span>地址：</label>' +
            '<select id="goodsProvince-' + addresstype + '" name="goodsProvince-' + addresstype + '" onChange="getCities(\'' + addresstype + '\')" style=" height:25px;width:120px">' +
            '<option value="">省份</option>' +
            '</select>' +
            '<select id="goodsCity-' + addresstype + '" name="goodsCity-' + addresstype + '" onChange="getCounties(\'' + addresstype + '\')" style=" height:25px;width:120px">' +
            '<option value="">城市</option> ' +
            '</select>' +
            '<select id="goodsCounty-' + addresstype + '" name="goodsCounty-' + addresstype + '" style=" height:25px;width:120px">' +
            '<option value="">区/县</option>' +
            '</select>' +
            '</li>' +
            '<li>' + zipStr +
            '<li>' +
            '<label><span>* </span>详细地址：</label>' +
            '<input type="text" style="width:410px;" id="goodsStreet-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label>邮箱：</label>' +
            '<input type="text" id="mail-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label><input type="checkbox" style="width:14px;height:14px;margin-top: -8px;" id="isCheck-' + addresstype + '" latag="latag_pc_ordersubmit_address_defaultcheck">&nbsp;&nbsp;</label>' +
            '设置为默认收货地址' +
            '</li>' +
            '<li style="padding-left: 50px;line-height: 13px;" >' +
            '<p>温馨提示：请确保以上信息准确无误，如发现有误请立即联系客服，避免因填写错误导致贵公司损失！</p></br>' +
            '<p>增值税专用发票在订单付款成功后由专人审核，正常情况下10个工作日内按收票地址寄出，请及时认证抵扣；</p></br>' +
            '<p>根据税务局要求，如发生退货，需购买方提供冲红通知单；税后扣除相关问题，由专业财务人员帮您处理。</p></br>' +
            '</li>' +
            '<li>' +
            '<label></label>' +
            '<button id="submitbtn-' + addresstype + '" onclick="submitInfo(\'' + addresstype + '\')" latag="latag_pc_ordersubmit_address_confirm">保存收货人信息</button>' +
            '</li>' +
            '</ul>' +
            '</div>';
    } else if (addresstype == AddressTypeEnums.DONGDE) {
        return '<div id="bg-' + addresstype + '" class="bg-n"></div>' +
            '<div style="display:none" class="box-' + addresstype + ' box">' +
            '<input type="hidden" id="flag1-' + addresstype + '" value="0">' +
            '<input type="hidden" id="deliveridupdate-' + addresstype + '" value="">' +
            '<a class="close" href="javascript:void(0);" latag="latag_pc_ordersubmit_address_closealert" onclick="closeAlert(\'' + addresstype + '\')">╳</a>' +
            '<ul>' +
            '<li>' +
            '<label><span>* </span>收货人：</label>' +
            '<input type="text" id="name-' + addresstype + '" >' +
            '<span style="color: #A79F9F;vertical-align: middle;padding-left: 5px;">请与身份证姓名保持一致</span>' +
            '<label id="alertName-' + addresstype + '" style="display:none;color:red;width: 100px;">收货人不能为空</label>' +
            '</li>' +
            '<li>' +
            '<label><span>* </span>手机：</label>' +
            '<input type="text" id="mobile-' + addresstype + '">' +
            '<label>  固定电话：</label>' +
            '<input type="text"  id="phone-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label><span>* </span>地址：</label>' +
            '<select id="s_province" name="s_province"  style=" height:25px;width:120px">' +
            '<option value="">省份</option>' +
            '</select>' +
            '<select id="s_city" name="s_city"  style=" height:25px;width:120px">' +
            '<option value="">城市</option> ' +
            '</select>' +
            '<select id="s_county" name="s_county" style=" height:25px;width:120px">' +
            '<option value="">区/县</option>' +
            '</select>' +
            '</li>' +
            ' <script type="text/javascript">' +
            '  _init_area();' +
            '</script>' +
            '<li>' +
            '<label><span>* </span>详细地址：</label>' +
            '<input type="text" style="width:410px;" id="goodsStreet-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label>邮箱：</label>' +
            '<input type="text" id="mail-' + addresstype + '">' +
            '<span style="color:red;vertical-align: middle;padding-left: 5px;">用来接收订单提醒邮件，便于您及时了解订单状态</span>' +
            '</li>' +
            '<li>' +
            '<label><input type="checkbox" style="width:14px;height:14px;margin-top: -8px;" id="isCheck-' + addresstype + '" latag="latag_pc_ordersubmit_address_defaultcheck">&nbsp;&nbsp;</label>' +
            '设置为默认收货地址' +
            '</li>' +
            '<li>' +
            '<label></label>' +
            '<button id="submitbtn-' + addresstype + '" onclick="submitInfo(\'' + addresstype + '\')" latag="latag_pc_ordersubmit_address_confirm">保存收货人信息</button>' +
            '</li>' +
            '</ul>' +
            '</div>';
    } else if (addresstype == AddressTypeEnums.HT) {
        return '<div id="bg-' + addresstype + '" class="bg-n"></div>' +
            '<div style="display:none" class="box-' + addresstype + ' box">' +
            '<input type="hidden" id="flag1-' + addresstype + '" value="0">' +
            '<input type="hidden" id="deliveridupdate-' + addresstype + '" value="">' +
            '<a class="close" href="javascript:void(0);" latag="latag_pc_ordersubmit_address_closealert" onclick="closeAlert(\'' + addresstype + '\')">╳</a>' +
            '<ul>' +
            '<li>' +
            '<label><span>* </span>收货人：</label>' +
            '<input type="text" id="name-' + addresstype + '" >' +
            '</li>' + companyStr +
            '<li>' +
            '<label><span>* </span>手机：</label>' +
            '<input type="text" id="mobile-' + addresstype + '">' +
            '<label>  固定电话：</label>' +
            '<input type="text"  id="phone-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label><span>* </span>地址：</label>' +
            '<select id="goodsProvince-' + addresstype + '" name="goodsProvince-' + addresstype + '" onChange="getCities(\'' + addresstype + '\')" style=" height:25px;width:120px">' +
            '<option value="">省份</option>' +
            '</select>' +
            '<select id="goodsCity-' + addresstype + '" name="goodsCity-' + addresstype + '" onChange="getCounties(\'' + addresstype + '\')" style=" height:25px;width:120px">' +
            '<option value="">城市</option> ' +
            '</select>' +
            '<select id="goodsCounty-' + addresstype + '" name="goodsCounty-' + addresstype + '" style=" height:25px;width:120px">' +
            '<option value="">区/县</option>' +
            '</select>' +
            '</li>' + zipStr +
            '<li>' +
            '<label><span>* </span>详细地址：</label>' +
            '<input type="text" style="width:410px;" id="goodsStreet-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label>邮箱：</label>' +
            '<input type="text" id="mail-' + addresstype + '">' +
            '</li>' +
            '<li>' +
            '<label><input type="checkbox" style="width:14px;height:14px;margin-top: -8px;" id="isCheck-' + addresstype + '" latag="latag_pc_ordersubmit_address_defaultcheck">&nbsp;&nbsp;</label>' +
            '设置为默认收货地址' +
            '</li>' +
            '<li>' +
            '<label></label>' +
            '<button id="submitbtn-' + addresstype + '" onclick="submitInfo(\'' + addresstype + '\')" latag="latag_pc_ordersubmit_address_confirm">保存收货人信息</button>' +
            '</li>' +
            '</ul>' +
            '</div>';
    } else {
        return "";
    }

}

//渲染支付方式
function showPayType(data, order, obj) {
    var flag = false;
    $("#box-b").empty();
    //console.log(obj);
    if(obj.checkoutType == "presell" ){
        flag = true;
    }
    if (data != null && data != "") {
        var paytypeStr = '<p>支付方式：</p>';
        if (shopId == 8) {
            paytypeStr = '<p>支付方式&nbsp;<span class="zffs_red">(发票内容只能开明细)</span>：</p>'
        }
        for (var i = 0; i < data.length; i++) {
            paytypeStr += ' <div style="cursor:pointer;" class="box-ax bgse" latag="latag_pc_ordersubmit_payonline" onclick="choosePay(' + data[i].type + ')" id="bgdiv' + data[i].type + '" value="' + data[i].type + '" >' +
                ' <p><span>' + data[i].name + '</span></p>' +
                ' <img src="' + pcCssHomeModule + '/images/pic-07.jpg' + '" id="icon">' +
                ' </div>';
        }
        if(flag){
            var preTel = $("#pre_tel").html();
            if(preTel == undefined){
                preTel = "";
            }
            var telHtml = "<div style='font-size: 14px;color: #635f5a;padding-top: 10px;'><img style='width: 30px;margin-left: 10px;margin-top: -5px;' src='" + pcCssHomeModule + "/images/warn.png'>尾款支付联系方式:<span id='thisPreTel'>" +preTel+"<input type='button' id='submitTel' onclick='changeTel()' value='修改'/></span></div>";
            paytypeStr += telHtml;
            var $presell = $("#presell_condition");
            if(  $presell != 'undefined'){
                $presell.remove();
            }
            $("#agree_condition").append("<span id='presell_condition'><a href='turnPresell.jhtm' class='blink' target='_blank' latag='latag_pc_odersubmit_turnb2c'>&   《预售协议》</a></span>"); // TODO 预售协议连接
        }
        paytypeStr += "<input id='presellflag' type='hidden' value='"+flag+"'/>";
        $("#box-b").append(paytypeStr);
        if (order != null && order != "") {
            $("#bgdiv" + order).addClass("pink").siblings().removeClass("pink");
        } else {
            $("#bgdiv" + data[0].type).addClass("pink").siblings().removeClass("pink");
        }
    }
    //updatePayType();
}
function changeTel(){
    var text = $("#pre_phone").val();
    var html = "<input type='text' id='textTel' value='"+text+"'/><input type='button' value='确定' onclick='confirmTel()'/>";
    $("#thisPreTel").html(html);
}
function confirmTel(){
    var preTel = $("#textTel").val();
    if(!check_mobile(preTel)){
        showMessage(3000, '请输入正确尾款联系手机号码!');
        $("#textTel").val("");
        $("#pre_phone").val("");
        return;
    }
    var newPreTel = hiddenMobile(preTel);
    var telHtml = newPreTel+"<input type='button' id='submitTel' onclick='changeTel()' value='修改'/>";
    $("#pre_phone").val(preTel);
    $("#thisPreTel").html(telHtml);
}
//渲染购物清单
function showCartList(data, order) {
    showProduct(data, order);
}
function showProduct(data, order) {
    //console.log(">>>>>>>>>>>");
    //console.log(data);
    if (!getCheckEmpty(data.saleTypeSet) && data.saleTypeSet[0] == 98) {//o2o
        iso2o = true;
    }
    $("#cto_personal").hide();
    $("#productList").empty();
    var moneyShow = "金额";
    if (shopId == 9) {
        moneyShow = "积分";
    }
    var productHeader = '<div class="box-tl"><p><a href="getcart.jhtm" latag="latag_pc_ordersubmit_backtocart">返回购物车修改></a>确认商品</p></div><div class="box-ls" style="margin-bottom: -20px;"><p class="tl-a">&nbsp;</p><p class="tl-b">商品名称</p><p class="tl-c">单价</p><p class="tl-d">数量</p><p class="tl-e">' + moneyShow + '</p></div>';
    $("#productList").append(productHeader);
    var productList = data.vendors;
    products_c = data.vendors;
    var $invoiceFaid = "";
    if($("#invoice_faid")){
        $invoiceFaid = $("#invoice_faid").val();
    }else{
        $("#productList").append("<input type='hidden' id='invoice_faid'/>");
        $invoiceFaid = "";
    }
    for (var i = 0; i < productList.length; i++) {
        if (getCheckEmpty($invoiceFaid)) {
            if (productList[i].type == 0 || productList[i].type == 3 || iso2o) {//直营，o2o
                $("#invoice_faid").val(productList[i].id);
            }
        }
        var sortedList = productList[i].sorted;
        for (var j = 0; j < sortedList.length; j++) {
            if (sortedList[j].itemType == 0 || sortedList[j].itemType == 5) {
                if (sortedList[j].item.salesType == 96) {
                    if (shopId == 9) {
                        var money = sortedList[j].item.num * sortedList[j].item.price;
                    } else {
                        var money = (sortedList[j].item.num * sortedList[j].item.price).toFixed(2);
                    }

                    if (null == sortedList[j].item.gspecStr || sortedList[j].item.gspecStr == "null") {
                        var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.id + '"><p class="list-a"><a href="javascript:;"><img src="' +
                            changeImgSize(sortedList[j].item.imgUrl, 90) + '"></a></p><p class="list-b"><a href="javascript:;">' + sortedList[j].item.name +
                            '</a><p class="list-c">' + sortedList[j].item.price + '</p><p class="list-d">' + sortedList[j].item.num +
                            '</p><p class="list-e">' + money + '</p>';
                        $("#productList").append(mainHtml);

                    } else {
                        var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.id + '"><p class="list-a"><a href="javascript:;"><img src="' +
                            changeImgSize(sortedList[j].item.imgUrl, 90) + '"></a></p><p class="list-b"><a href="javascript:;">' + sortedList[j].item.name + '&nbsp;[' +
                            sortedList[j].item.gspecStr + ']</a><p class="list-c">' + sortedList[j].item.price + '</p><p class="list-d">' + sortedList[j].item.num +
                            '</p><p class="list-e">' + money + '</p>';
                        $("#productList").append(mainHtml);
                    }
                    var personalStr = '';
                    var cvItemlength = sortedList[j].item.skuExtend.cvItemList.length;
                    var itemArr = [];
                    for (var m = 0; m < cvItemlength; m++) {
                        if (sortedList[j].item.skuExtend.cvItemList[m].isselect == "1") {
                            itemArr.push(sortedList[j].item.skuExtend.cvItemList[m]);
                        }
                    }
                    for (var h = 0; h < itemArr.length; h = h + 2) {
                        if ((h + 1) == itemArr.length) {
                            personalStr = personalStr + '<tr><td width="15%">' + itemArr[h].char_des + '</td> <td width="35%">' + itemArr[h].charvalue_des + '</td> <td width="15%"></td> <td width="35%"></td> </tr>';
                        } else {
                            personalStr = personalStr + '<tr><td width="15%">' + itemArr[h].char_des + '</td> <td width="35%">' + itemArr[h].charvalue_des + '</td> <td width="15%">' + itemArr[h + 1].char_des + '</td> <td width="35%">' + itemArr[h + 1].charvalue_des + '</td> </tr>';
                        }
                    }
                    $(".config_table").empty().append(personalStr);
                    if (sortedList[j].item.thinkRemark != "") {
                        var thinkRemark = JSON.parse(sortedList[j].item.thinkRemark);
                        var custom_i = JSON.parse(thinkRemark.custom);
                        if (custom_i.personalization.pageA.imageUrl) {
                            var pagea_img = '<span class="span_top">效果图:</span><img class="personal_img" src="' + changeImgSize(custom_i.personalization.pageA.imageUrl, 80) + '" alt="">';
                            var customLaser = thinkRemark.customLaserPreviewDTO.customLaser;
                            if (customLaser) {
                                customLaser = '<b>' + customLaser + '</b>';
                            } else {
                                customLaser = "";
                            }
                            var pagec_char = '<ul class="left"><li><span>文字：</span>' + customLaser + ' </li>  </ul>';

                            $(".config_table").empty().append(personalStr);
                            $("#personal_imga").empty().append(pagea_img);
                            $("#pagec_char").empty().append(pagec_char);
                            if (thinkRemark.customTextPreviewDTO.fontColor) {
                                $(thinkRemark.customTextPreviewDTO.fontColor.value).append('<img src="http://lenovopic.app.lefile.cn/icon/selected.png">');
                            }
                            $("#cto_personal").show();
                        }

                    } else {
                        $(".dsix_boxg_cont").eq(1).hide();
                        $(".dsix_boxg_cont").eq(2).hide();
                        if (itemArr.length > 0) {
                            $("#cto_personal").show();
                        }
                    }

                } else {
                    if (shopId == 9) {
                        var money = sortedList[j].item.num * sortedList[j].item.price;
                    } else {
                        var money = (sortedList[j].item.num * sortedList[j].item.price).toFixed(2);
                    }
                    if (null == sortedList[j].item.gspecStr || sortedList[j].item.gspecStr == "null") {
                        var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.id + '"><p class="list-a"><a href="'+ sortedList[j].item.url + '"><img src="' +
                            changeImgSize(sortedList[j].item.imgUrl, 90) + '"></a></p><p class="list-b"><a href="' + sortedList[j].item.url + '">' + sortedList[j].item.name +
                            '</a><p class="list-c">' + sortedList[j].item.price + '</p><p class="list-d">' + sortedList[j].item.num +
                            '</p><p class="list-e">' + money + '</p>';
                        $("#productList").append(mainHtml);
                        if(sortedList[j].item.isNeedSN == 1){
                            var sn_code = sortedList[j].item.sn;
                            if(null == sn_code || sn_code == '' || typeof(sn_code) == 'undefined'){
                                sn_code = '';
                            }
                            var snCode = '<div class="dan"><p class="list-b">SN码：<input type="text" readonly="readonly" disabled="true" id="sncode_'+sortedList[j].item.id+"_"+sortedList[j].item.materialCode+'" value="' + sn_code + '"></p></div>';
                            $("#productList").append(snCode);
                        }
                    } else {
                        var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.id + '"><p class="list-a"><a href="'+ sortedList[j].item.url + '"><img src="' +
                            changeImgSize(sortedList[j].item.imgUrl, 90) + '"></a></p><p class="list-b"><a href="' + sortedList[j].item.url + '">' + sortedList[j].item.name + '&nbsp;[' +
                            sortedList[j].item.gspecStr + ']</a></p><p class="list-c">' + sortedList[j].item.price + '</p><p class="list-d">' + sortedList[j].item.num +
                            '</p><p class="list-e">' + money + '</p>'
                        if (type_t == "dongde") {
                            mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.id + '"><p class="list-a"><a href="' + sortedList[j].item.url + '"><img src="' +
                                changeImgSize(sortedList[j].item.imgUrl, 90) + '"></a></p><p class="list-b"><a href="'+ sortedList[j].item.url + '">' + sortedList[j].item.name + '</a><br><span style="color:#7c7c7c">描述：' + sortedList[j].item.dongPackInfo.productDesc + '</span><br><span style="color:#7c7c7c">已选号码：' + sortedList[j].item.phoneServiceNumber + ',' + sortedList[j].item.cacGoodsinfoes.sfAraeCodeName + '</span></p><p class="list-c">' + sortedList[j].item.price + '</p><p class="list-d">' + sortedList[j].item.num +
                                '</p><p class="list-e">' + money + '</p>';
                        }
                        $("#productList").append(mainHtml);
                        if(sortedList[j].item.isNeedSN == 1){
                            var sn_code = sortedList[j].item.sn;
                            if(null == sn_code || sn_code == '' || typeof(sn_code) == 'undefined'){
                                sn_code = '';
                            }
                            var snCode = '<div class="dan"><p class="list-b">SN码：<input type="text" readonly="readonly" disabled="true" id="sncode_'+sortedList[j].item.id+'" value="' + sn_code + '"></p></div>';
                            $("#productList").append(snCode);
                        }
                    }

                }
                if (sortedList[j].item.gifts.length != 0) {
                    $("#" + sortedList[j].item.id).css("border-bottom", "none");
                    var giftheader = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">赠品：</div><ul id="giftUl' + j + '">';
                    $("#productList").append(giftheader);
                    for (var k = 0; k < sortedList[j].item.gifts.length; k++) {
                        var giftHtml = '<li class="clearfix"><a href="' + sortedList[j].item.gifts[k].url + '"><img src="' + changeImgSize(sortedList[j].item.gifts[k].imgUrl, 80) +
                            '" ></a><a href="' + sortedList[j].item.gifts[k].url + '" class="bc_gift_name">' + sortedList[j].item.gifts[k].name + '</a><span>&nbsp;</span><span class="nums-a">' +
                            sortedList[j].item.gifts[k].num + '</span><span class="nums-b">&nbsp;</span></li>';
                        $("#giftUl" + j).append(giftHtml);
                    }
                    var giftfooter = '</ul></div>';
                    $("#productList").append(giftfooter);
                }
                if (sortedList[j].item.services.length != 0) {
                    $("#" + sortedList[j].item.id).css("border-bottom", "none");
                    for (var k = 0; k < sortedList[j].item.services.length; k++) {
                        var money = (sortedList[j].item.services[k].num * sortedList[j].item.services[k].price).toFixed(2);
                        var serviceHtml = '<div class="box-ltx"><p class="list-aa">服务：' + sortedList[j].item.services[k].name + '</p><p class="list-c">' +
                            sortedList[j].item.services[k].price + '</p><p class="list-d">' + sortedList[j].item.services[k].num + '</p><p class="list-e">' + money + '</p></div>';

                        $("#productList").append(serviceHtml);
                    }
                }
                if (null != sortedList[j].item.thinkCustomInfo) {
                    $("#" + sortedList[j].item.id).css("border-bottom", "none");
                    var dzHtml = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">定制：</div><ul><li class="clearfix"><a href=""><img src="' + changeImgSize(sortedList[j].item.thinkCustomInfo.display, 80) +
                        '"></a><a href="" class="bc_gift_name">' + sortedList[j].item.thinkCustomInfo.custominfo.customname + '</a><span>&nbsp;</span><span class="nums-a">&nbsp;</span><span class="nums-b">&nbsp;</span></li></ul></div>';
                    $("#productList").append(dzHtml);
                }
                /*数据恢复险*/
                var datarecovery = sortedList[j].item.recoveryService;
                if (datarecovery) {
                    $("#" + sortedList[j].item.id).css("border-bottom", "none");
                    var money = (datarecovery.num * datarecovery.price).toFixed(2);
                    var serviceHtml = '<div class="box-ltx db_back" id="dr' + sortedList[j].item.id + '"><p class="list-aa"><span style="color:red;">数据恢复险：</span><i class="i_checkbox" onclick="dataRecoveryClick(this,\'' + sortedList[j].item.id + '\',\'' + sortedList[j].item.itemId + '\')" ></i><a href="' + datarecovery.url + '">原价199元,活动价<span style="color:red;">' + datarecovery.price + '</span>元,软件数据恢复服务（远程，1年有效期）</a><b><i class="i_title" style="display: none;"><span class="db_body">针对联想出厂PC出现因软件原因导致的数据丢失，提供软件数据恢复服务（远程），1年有效期</span></i><span class="jiao1" style="display: none;"></span><span class="jiao2" style="display: none;"></span> <img class="title_img" onmouseover="title_imgShow(this)" onmouseout="title_imgHide(this)" src="http://lenovopic.app.lefile.cn/icon/title.png"></b></p><p class="list-c">' +
                        datarecovery.price + '</p><p class="list-d">' + datarecovery.num + '</p><p class="list-e">' + money + '</p></div>';
                    $("#productList").append(serviceHtml);
                }
            } else if (sortedList[j].itemType == 3 || sortedList[j].itemType == 2) {
                var titlenameP = '套餐';
                if (sortedList[j].itemType == 2) {
                    titlenameP = '选件';
                }
                var skuslen = sortedList[j].item.skus.length;
                var clen = 0;
                for (var n = 0; n < skuslen; n++) {
                    if (sortedList[j].item.mainSkuId && sortedList[j].item.mainSkuId != sortedList[j].item.skus[n].id) {//套餐
                        if (skuslen == 2) {
                            var packageHeader = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">' + titlenameP + '：</div><ul id="packageUl' + j + '"></ul></div>';
                            $("#productList").append(packageHeader);
                            var packageHtml = '<li class="clearfix"><a href="' + sortedList[j].item.skus[n].url + '"><img src="' + changeImgSize(sortedList[j].item.skus[n].imgUrl, 80) +
                                '" ></a><a href="'+ sortedList[j].item.skus[n].url+'" class="bc_gift_name">' + sortedList[j].item.skus[n].name + '</a><span>' +
                                sortedList[j].item.skus[n].price + '</span><span class="nums-a">' +
                                sortedList[j].item.skus[n].num + '</span><span class="nums-b"></span></li>';
                            $("#packageUl" + j).append(packageHtml);
                        } else if (skuslen > 2) {
                            if (clen == 0) {
                                var packageHeader = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">' + titlenameP + '：</div><ul id="packageUl' + j + '"></ul></div>';
                                $("#productList").append(packageHeader);
                                var packageHtml = '<li class="clearfix"><a href="' + sortedList[j].item.skus[n].url + '"><img src="' + changeImgSize(sortedList[j].item.skus[n].imgUrl, 80) +
                                    '" ></a><a href="' + sortedList[j].item.skus[n].url+'" class="bc_gift_name">' + sortedList[j].item.skus[n].name + '</a><span>' +
                                    sortedList[j].item.skus[n].price + '</span><span class="nums-a">' +
                                    sortedList[j].item.skus[n].num + '</span><span class="nums-b"></span></li>';
                                $("#packageUl" + j).append(packageHtml);
                                clen = clen + 1;
                            } else {
                                var packageHtml = '<li class="clearfix"><a href="' +  sortedList[j].item.skus[n].url + '"><img src="' + changeImgSize(sortedList[j].item.skus[n].imgUrl, 80) +
                                    '" ></a><a href="'+ sortedList[j].item.skus[n].url + '" class="bc_gift_name">' + sortedList[j].item.skus[n].name + '</a><span>' +
                                    sortedList[j].item.skus[n].price + '</span><span class="nums-a">' +
                                    sortedList[j].item.skus[n].num + '</span><span class="nums-b"></span></li>';
                                $("#packageUl" + j).append(packageHtml);
                            }
                        }
                    } else {
                        if (shopId == 9) {
                            var money = sortedList[j].item.skus[n].num * sortedList[j].item.skus[n].price;
                        } else {
                            var money = (sortedList[j].item.skus[n].num * sortedList[j].item.skus[n].price).toFixed(2);
                        }
                        if (null == sortedList[j].item.skus[n].gspecStr || sortedList[j].item.skus[n].gspecStr == "null") {
                            var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.skus[n].id + '"><p class="list-a"><a href="'  + sortedList[j].item.skus[n].url + '"><img src="' +
                                changeImgSize(sortedList[j].item.skus[n].imgUrl, 80) + '"></a></p><p class="list-b"><a href="'  + sortedList[j].item.skus[n].url + '">' + sortedList[j].item.skus[n].name +
                                '</a><p class="list-c">' + sortedList[j].item.skus[n].price + '</p><p class="list-d">' + sortedList[j].item.skus[n].num +
                                '</p><p class="list-e">' + money + '</p>';
                            $("#productList").append(mainHtml);
                        } else {
                            var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.skus[n].id + '"><p class="list-a"><a href="' + sortedList[j].item.skus[n].url + '"><img src="' +
                                changeImgSize(sortedList[j].item.skus[n].imgUrl, 80) + '"></a></p><p class="list-b"><a href="'  + sortedList[j].item.skus[n].url + '">' + sortedList[j].item.skus[n].name + '&nbsp;[' +
                                sortedList[j].item.skus[n].gspecStr + ']</a><p class="list-c">' + sortedList[j].item.skus[n].price + '</p><p class="list-d">' + sortedList[j].item.skus[n].num +
                                '</p><p class="list-e">' + money + '</p>';
                            $("#productList").append(mainHtml);
                        }

                        if (sortedList[j].item.skus[n].gifts.length != 0) {
                            $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                            var giftheader = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">赠品：</div><ul id="giftUl' + j + '"></ul></div>';
                            $("#productList").append(giftheader);
                            for (var k = 0; k < sortedList[j].item.skus[n].gifts.length; k++) {
                                var giftHtml = '<li class="clearfix"><a href="'  + sortedList[j].item.skus[n].gifts[k].url + '"><img src="' + changeImgSize(sortedList[j].item.skus[n].gifts[k].imgUrl, 80) +
                                    '" ></a><a href="' + sortedList[j].item.skus[n].gifts[k].url + '" class="bc_gift_name">' + sortedList[j].item.skus[n].gifts[k].name + '</a><span>&nbsp;</span><span class="nums-a">' +
                                    sortedList[j].item.skus[n].gifts[k].num + '</span><span class="nums-b">&nbsp;</span></li>';
                                $("#giftUl" + j).append(giftHtml);
                            }
                        }
                        if (sortedList[j].item.skus[n].services.length != 0) {
                            $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                            for (var k = 0; k < sortedList[j].item.skus[n].services.length; k++) {
                                var money = (sortedList[j].item.skus[n].services[k].num * sortedList[j].item.skus[n].services[k].price).toFixed(2);
                                var serviceHtml = '<div class="box-ltx"><p class="list-aa">服务：' + sortedList[j].item.skus[n].services[k].name + '</p><p class="list-c">' +
                                    sortedList[j].item.skus[n].services[k].price + '</p><p class="list-d">' + sortedList[j].item.skus[n].services[k].num + '</p><p class="list-e">' + money + '</p></div>';

                                $("#productList").append(serviceHtml);
                            }
                        }
                        if (null != sortedList[j].item.skus[n].thinkCustomInfo) {
                            $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                            var dzHtml = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">定制：</div><ul><li class="clearfix"><a href=""><img src="' + changeImgSize(sortedList[j].item.skus[n].thinkCustomInfo.display, 80) +
                                '"></a><a href="" class="bc_gift_name">' + sortedList[j].item.skus[n].thinkCustomInfo.custominfo.customname + '</a><span>&nbsp;</span><span class="nums-a">&nbsp;</span><span class="nums-b">&nbsp;</span></li></ul></div>';
                            $("#productList").append(dzHtml);
                        }
                        /*数据恢复险*/
                        var datarecovery = sortedList[j].item.skus[n].recoveryService;
                        if (datarecovery) {
                            $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                            var money = ( datarecovery.num * datarecovery.price).toFixed(2);
                            var serviceHtml = '<div class="box-ltx db_back" id="dr' + sortedList[j].item.skus[n].id + '"><p class="list-aa"><span style="color:red">数据恢复险：</span><i class="i_checkbox" onclick="dataRecoveryClick(this,\'' + sortedList[j].item.id + '\',\'' + sortedList[j].item.skus[n].itemId + '\')"></i><a href="' +  datarecovery.url + '">原价199元,活动价<span style="color:red;">' + datarecovery.price + '</span>元,软件数据恢复服务（远程，1年有效期）</a><b><i class="i_title" style="display: none;"><span class="db_body">针对联想出厂PC出现因软件原因导致的数据丢失，提供软件数据恢复服务（远程），1年有效期</span></i><span class="jiao1" style="display: none;"></span><span class="jiao2" style="display: none;"></span> <img class="title_img" onmouseover="title_imgShow(this)" onmouseout="title_imgHide(this)" src="http://lenovopic.app.lefile.cn/icon/title.png"></b></p><p class="list-c">' +
                                datarecovery.price + '</p><p class="list-d">' + datarecovery.num + '</p><p class="list-e">' + money + '</p></div>';
                            $("#productList").append(serviceHtml);
                        }
                        $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                    }
                }
            } else {
                for (var n = 0; n < sortedList[j].item.skus.length; n++) {
                    if (shopId == 9) {
                        var money = sortedList[j].item.skus[n].num * sortedList[j].item.skus[n].price;
                    } else {
                        var money = (sortedList[j].item.skus[n].num * sortedList[j].item.skus[n].price).toFixed(2);
                    }
                    if (null == sortedList[j].item.skus[n].gspecStr || sortedList[j].item.skus[n].gspecStr == "null") {
                        var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.skus[n].id + '"><p class="list-a"><a href="' +  sortedList[j].item.skus[n].url + '"><img src="' +
                            changeImgSize(sortedList[j].item.skus[n].imgUrl, 90) + '"></a></p><p class="list-b"><a href="' +  sortedList[j].item.skus[n].url + '">' + sortedList[j].item.skus[n].name +
                            '</a><p class="list-c">' + sortedList[j].item.skus[n].price + '</p><p class="list-d">' + sortedList[j].item.skus[n].num +
                            '</p><p class="list-e">' + money + '</p>';
                        $("#productList").append(mainHtml);
                    } else {
                        var mainHtml = '<div class="divide" style="margin-top: 20px;border-bottom: 1px solid #d9d8d6;"></div><div class="list" id="' + sortedList[j].item.skus[n].id + '"><p class="list-a"><a href="'+ sortedList[j].item.skus[n].url + '"><img src="' +
                            changeImgSize(sortedList[j].item.skus[n].imgUrl, 90) + '"></a></p><p class="list-b"><a href="' + sortedList[j].item.skus[n].url + '">' + sortedList[j].item.skus[n].name + '&nbsp;[' +
                            sortedList[j].item.skus[n].gspecStr + ']</a><p class="list-c">' + sortedList[j].item.skus[n].price + '</p><p class="list-d">' + sortedList[j].item.skus[n].num +
                            '</p><p class="list-e">' + money + '</p>';
                        $("#productList").append(mainHtml);
                    }

                    if (sortedList[j].item.skus[n].gifts.length != 0) {
                        $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                        var giftheader = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">赠品：</div><ul id="giftUl' + j + '"></ul></div>';
                        $("#productList").append(giftheader);
                        for (var k = 0; k < sortedList[j].item.skus[n].gifts.length; k++) {
                            var giftHtml = '<li class="clearfix"><a href="'+ sortedList[j].item.skus[n].gifts[k].url + '"><img src="' + changeImgSize(sortedList[j].item.skus[n].gifts[k].imgUrl, 80) +
                                '" ></a><a href="' + sortedList[j].item.skus[n].gifts[k].url + '" class="bc_gift_name">' + sortedList[j].item.skus[n].gifts[k].name + '</a><span>&nbsp;</span><span class="nums-a">' +
                                sortedList[j].item.skus[n].gifts[k].num + '</span><span class="nums-b">&nbsp;</span></li>';
                            $("#giftUl" + j).append(giftHtml);
                        }
                    }
                    if (sortedList[j].item.skus[n].services.length != 0) {
                        $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                        for (var k = 0; k < sortedList[j].item.skus[n].services.length; k++) {
                            var money = (sortedList[j].item.skus[n].services[k].num * sortedList[j].item.skus[n].services[k].price).toFixed(2);
                            var serviceHtml = '<div class="box-ltx"><p class="list-aa">服务：' + sortedList[j].item.skus[n].services[k].name + '</p><p class="list-c">' +
                                sortedList[j].item.skus[n].services[k].price + '</p><p class="list-d">' + sortedList[j].item.skus[n].services[k].num + '</p><p class="list-e">' + money + '</p></div>';

                            $("#productList").append(serviceHtml);
                        }
                    }
                    if (null != sortedList[j].item.skus[n].thinkCustomInfo) {
                        $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                        var dzHtml = '<div class="bc_gift_bot clearfix"><div class="bc_bot_title">定制：</div><ul><li class="clearfix"><a href=""><img src="' + changeImgSize(sortedList[j].item.skus[n].thinkCustomInfo.display, 80) +
                            '"></a><a href="" class="bc_gift_name">' + sortedList[j].item.skus[n].thinkCustomInfo.custominfo.customname + '</a><span>&nbsp;</span><span class="nums-a">&nbsp;</span><span class="nums-b">&nbsp;</span></li></ul></div>';
                        $("#productList").append(dzHtml);
                    }
                    /*数据恢复险*/
                    var datarecovery = sortedList[j].item.skus[n].recoveryService;
                    if (datarecovery) {
                        $("#" + sortedList[j].item.skus[n].id).css("border-bottom", "none");
                        var money = (datarecovery.num * datarecovery.price).toFixed(2);
                        var serviceHtml = '<div class="box-ltx db_back" id="dr' + sortedList[j].item.skus[n].id + '"><p class="list-aa"><span style="color:red">数据恢复险：</span><i class="i_checkbox" onclick="dataRecoveryClick(this,\'' + sortedList[j].item.id + '\',\'' + sortedList[j].item.skus[n].itemId + '\')"></i><a href="' + productDetail + '/' + datarecovery.id + '&#46;html">原价199元,活动价<span style="color:red;">' + datarecovery.price + '</span>元,软件数据恢复服务（远程，1年有效期）</a><b><i class="i_title" style="display: none;"><span class="db_body">针对联想出厂PC出现因软件原因导致的数据丢失，提供软件数据恢复服务（远程），1年有效期</span></i><span class="jiao1" style="display: none;"></span><span class="jiao2" style="display: none;"></span> <img class="title_img" onmouseover="title_imgShow(this)" onmouseout="title_imgHide(this)" src="http://lenovopic.app.lefile.cn/icon/title.png"></b></p><p class="list-c">' +
                            datarecovery.price + '</p><p class="list-d">' + datarecovery.num + '</p><p class="list-e">' + money + '</p></div>';
                        $("#productList").append(serviceHtml);
                    }
                }
            }
        }
    }
    if (order) {
        $(".db_back").each(function (i, n) {
            $(n).removeClass("db_checked")

        });
        var drArr = order.split(",");
        for (var i = 0; i < drArr.length; i++) {
            $("#dr" + drArr[i]).addClass("db_checked")
        }
    }
}
function changeImgSize(img, size) {
    if (img && img.indexOf("pic.17.lenovo.com.cn") < 0) {
        return img.replace(img.split('.')[img.split('.').length - 1], "w" + size + "." + img.split('.')[img.split('.').length - 1]);
    } else {
        return img;
    }
}
//数据恢复险
function datarecovery(id, itemid, check) {
    var ajaxdata = {itemId: itemid.toString(), check: check, direct: buyType};
    $.ajax({
        type: "post",
        url: buy_order.URL.datarecovery(),
        async: false,
        data: ajaxdata,
        dataType: "json",
        success: function (data) {
            if (data != null) {
                if (data.rc != null && data.rc == "0") {
                    updatedatarecovery();
                } else {
                    $("#dr" + id).parents(".db_back").removeClass("db_checked");
                    if (null != data.msg && '' != data.msg) {
                        showMessage(3000, data.msg);
                    } else {
                        showMessage(3000, "系统繁忙，更新结算缓存失败，请稍后再试！");
                    }
                }
            }
        }
    });
}
//渲染优惠券列表
function showCouponList(data, order,discountsViewInfo) {
    if(discountsViewInfo != "" && discountsViewInfo.showCoupon == 0){
        $("#couponlist").hide();
    }
    if (data != null && data != "") {
        showCoupon(data, order);
    }
}
//渲染优惠码
function showCouponCode(order,discountsViewInfo) {
    if(discountsViewInfo != "" && discountsViewInfo.showCouponCode == 0){
        $("#couponcodeDiv").hide();
    }
    if (order != null && order != "") {
        $("#couponcode").val(order);
        $("#couponcheck").attr("checked", true);
        $("#couponcode").attr("readonly", true);
    }
}
//渲染增票
function showInvoice(data, order) {
    if (data || shopId == 8) {
        checkshow(data, order);
    }
}
//渲染价格
function showPrice(data,order) {
    var flag = false;
    if(order.checkoutType == "presell" ){
        flag = true;
    }
    if (data == "") {
        $("#discountinfo").css("display", "none");
    } else {
        $("#zj").text(data.allCouponDiscount);
        $("#totalPrice").text("￥" + data.totalPrice);
        if (data.totalDiscount != 0) {
            $("#totaldiscount").text("-￥" + data.totalDiscount);
        } else {
            $("#totaldiscount").text("￥" + data.totalDiscount);
        }
        if (data.allCouponDiscountWithCode != 0) {
            $("#youhuij").text("-￥" + data.allCouponDiscountWithCode);
        } else {
            $("#youhuij").text("￥" + data.allCouponDiscountWithCode);
        }
        $("#freight").text("￥" + data.freight);
        $("#paymoney").text("￥" + data.totalPay);
        if(flag){
            $("#payDeposit").text("￥" + data.depositPrice);
            $("#finalPrice").text("￥" + data.restPrice);
            $("#p_freight").css("display","none");
            $("#p_paymoney").css("display","none");
            $("#p_payDeposit").css("display","block");
            $("#p_restPrice").css("display","block");
            $("#tiptext").css("display","block");
        }else{
            $("#p_freight").css("display","block");
            $("#p_paymoney").css("display","block");
            $("#p_payDeposit").css("display","none");
            $("#p_restPrice").css("display","none");
            $("#tiptext").css("display","none");
        }

        $("#discountinfo").css("display", "block");
    }
}
function showScores(data) {
    $("#discountinfo").empty();
    var scoreStr = '<p><span>当前积分：<em style="color: #e2231a;font-weight: bold;font-style: normal;" >' + data.totalScore + '</em></span></p>' +
        '<p><span>兑换使用积分：<em style="color: #e2231a;font-weight: bold;font-style: normal;" >' + data.totalPay + '</em></span></p>' +
        '<p id="submitbutton" style="margin-bottom: 15px;"><button onclick="submitOrder()" event-name="PC端_提交订单"  style="font-size: 18px;cursor: pointer;margin-top: 2px;">提交订单</button></p>';
    $("#discountinfo").append(scoreStr);
}
//设置众筹订单数据
function showzc(data) {
    var zcvalue = data[0];
    if (zcvalue == 97) {
        $("#discount").css("display", "none");
        $("#pricesubmit").css("display", "none");

    } else {
        $("#discount").css("display", "block");
        $("#pricesubmit").css("display", "block");
    }
}
//渲染内购额度组件
function showInnerBuyWidget(data, order) {
    if (data == "") {
        $("#innerlimitmoney").css("display", "none");
    } else {
        if (data.isCanUseInner == 0) {
            $("#innerlimitmoney").css("display", "none");
        }
        if (data.isCanUseInner == 1) {
            $("#userCanuseInnerBuy").text(data.totalInner);
            $("#innerbuySum").text(data.maxUseInner);
            $("#innerlimitmoney").css("display", "block");
        }
    }
    if (order != null && order != "") {
        $("#innerLimitMoney").val(order);
        $("#innerLimitcheck").attr("checked", true);
        $("#innerLimitMoney").attr("readonly", true);
    }
}
//渲染乐豆组件
function showHappyBeanWidget(data, order,discountsViewInfo) {
    if (data == "" || (discountsViewInfo != "" && discountsViewInfo.showLeBean == 0)) {
        $("#happyBeanNum").css("display", "none");
    } else {
        if (data.isCanUseLeBean == 0) {
            $("#happyBeanNum").css("display", "none");
        }
        if (data.isCanUseLeBean == 1) {
            $("#LeDouTotalCount").text(data.totalLeBean);
            $("#availableHappyBeanNum").text(data.usableLeBean);
            $("#happyBeanNum").css("display", "block");
        }
    }
    if (order != null && order != "") {
        if (order == 0) {
            $("#useHappyBeanNum").val("");
            $("#happyBeancheck").attr("checked", false);
            $("#useHappyBeanNum").removeAttr("readonly");
        } else {
            $("#useHappyBeanNum").val(order);
            $("#happyBeancheck").attr("checked", true);
            $("#useHappyBeanNum").attr("readonly", true);
        }

    }
}
//展示sn
function showsn(data, order) {
    if (data) {
        $("#sncode").css("display", "block");
    } else {
        $("#sncode").css("display", "none");
    }
    if (order != null && order != "") {
        $("#sercicecode").val(order);
        $("#sncheck").attr("checked", true);
        $("#sercicecode").attr("readonly", true);
    }
}
/////////////////////////////////////////////////
//获取数据（渲染、展示）--结束
////////////////////////////////////////////////

/////////////////////////////////////////////////
//更新缓存--开始
////////////////////////////////////////////////
function updateMoreCheckOutCache(invoice_order, isSendContract_order) {
    var invoice_u = "";
    if (invoice_order) {
        invoice_u = invoice_order;
    } else {
        invoice_u = getInvoice11();
    }
    var paywaydata = getPayWay();
    var ajaxdata = {
        lid: lid, shopId: shopId, terminal: terminal,
        cacheItems: [UpdateBackFillItem.DELIVER, UpdateBackFillItem.INVOICE, UpdateBackFillItem.PAYTYPE],
        consigneeId: getChoseId(type_t == "dongde" ? AddressTypeEnums.DONGDE : AddressTypeEnums.SH),
        invoice: invoice_u,
        paytype: paywaydata,
        ss: new Date().getTime()
    }
    if (shopId == 8 && !isSendContract_order) {
        ajaxdata.cacheItems.push(UpdateBackFillItem.CONTRACTADDRESS);
        ajaxdata.cacheItems.push(UpdateBackFillItem.CONTRACTISCONSIGNEE);
        ajaxdata.cacheItems.push(UpdateBackFillItem.ISSENDCONTRACT);
        ajaxdata.contractIsConsigneeId = "0";
        ajaxdata.contractAddressId = "";
        ajaxdata.isSendContract = "0";
    }
    updateCheckOutCacheList(ajaxdata, null);
}
function updateCheckOutCacheList(ajaxdata, addresstype) {
    $.post(buy_order.URL.updateMoreCheckOutCache(), ajaxdata, function (data) {
        if (data != null) {
            if (data.rc == 0) {//更新缓存成功
                if (addresstype && addresstype == AddressTypeEnums.HT) {
                    contractAddressOperate(ajaxdata.isSendContract, ajaxdata.contractIsConsigneeId, ajaxdata.contractAddressId);
                } else if (addresstype && addresstype == AddressTypeEnums.SP) {
                    invoiceAddressOperate(ajaxdata.invoiceIsConsigneeId, ajaxdata.invoiceAddressId);
                }
            } else {
                if (null != data.msg && '' != data.msg && 'undefined' != data.msg) {
                    showMessage(3000, data.msg);
                } else {
                    showMessage(3000, "系统繁忙，更新结算缓存失败，请稍后再试！");
                }
            }
        }
    }, 'json');
}
/*address param*/
function makeContentParam(content, param) {
    var isCheckout = false;
    if (content != "") {
        /*
         开头为D
         删除地址----content传递"D"+consigneeId
         开头为A
         只更新地址没有对默认地址的状态进行修改---content只传递"A"
         更新地址又同时修改默认地址的状态            ---content传递"A"+consigneeId
         其他情况不做任何处理--（更新地址缓存）不需要checkout
         */
        var content_temp = content;
        var consigneeStatus = content.substring(0, 1);
        content = content.substring(1);
        if (consigneeStatus == "D") {//删除
            if (param == content) {
                param = "";
            }
            content = param;
            isCheckout = true;
        } else if (consigneeStatus == "A") {//新增或是更新或是只是刷新
            if (content == "") {
                content = param;
            }
            isCheckout = true;
        } else {
            content = content_temp;
            param = content_temp;
        }
    } else {
        param = "";
    }
    dataContent = {};
    dataContent.isCheckout = isCheckout;
    dataContent.content = content;
    dataContent.shareParam = param;
    return dataContent;
}
function updateCheckOutCache(updateItem, content) {
    var isCheckout = false;
    var deliverData;
    if (updateItem == UpdateBackFillItem.DELIVER) {
        deliverData = makeContentParam(content, shareConsigneeId);
        shareConsigneeId = deliverData.shareParam;
        isCheckout = deliverData.isCheckout;
        content = deliverData.content;
    } else if (updateItem == UpdateBackFillItem.INVOICEADDRESS) {
        deliverData = makeContentParam(content, shareInvoiceAddressId);
        shareInvoiceAddressId = deliverData.shareParam;
        isCheckout = deliverData.isCheckout;
        content = deliverData.content;
    } else if (updateItem == UpdateBackFillItem.CONTRACTADDRESS) {
        deliverData = makeContentParam(content, shareContractAddressId);
        shareContractAddressId = deliverData.shareParam;
        isCheckout = deliverData.isCheckout;
        content = deliverData.content;
    }
    $.post(buy_order.URL.updateCheckOutCache(), {
        lid: lid,
        shopId: shopId,
        terminal: terminal,
        cacheItem: updateItem,
        content: content,
        ss: new Date().getTime()
    }, function (data) {
        if (data != null) {
            if (data.rc == 0) {//更新缓存成功
                if (updateItem == UpdateBackFillItem.ISSENDCONTRACT || updateItem == UpdateBackFillItem.CONTRACTISCONSIGNEE || updateItem == UpdateBackFillItem.INVOICEISCONSIGNEE || updateItem == UpdateBackFillItem.INVOICE || updateItem == UpdateBackFillItem.PAYTYPE) {
                    //地址、发票、支付方式 ,收票地址是否同收货地址,合同地址是否同收货地址,是否寄送合同不需要checkout
                } else {
                    if (updateItem == UpdateBackFillItem.DELIVER || updateItem == UpdateBackFillItem.INVOICEADDRESS || updateItem == UpdateBackFillItem.CONTRACTADDRESS) {
                        if (isCheckout) {
                            getcheckOutData(global_ajaxdomain, terminal);
                        }
                    } else {
                        getcheckOutDataNew(global_ajaxdomain, terminal, updateItem);//更新缓存成功--重新渲染
                    }
                }
            } else {
                cleanInput(updateItem, 1);
                if (null != data.msg && '' != data.msg && 'undefined' != data.msg) {
                    showMessage(3000, data.msg);
                } else {
                    showMessage(3000, "系统繁忙，更新结算缓存失败，请稍后再试！");
                }
            }
        }
    }, 'json');
}
function updateCheckOutCacheNew(updateItem, content) {
    $.post(buy_order.URL.updateCheckOutCache(), {
        lid: lid,
        shopId: shopId,
        terminal: terminal,
        cacheItem: updateItem,
        content: content,
        ss: new Date().getTime()
    }, function (data) {
        if (data != null) {
            if (data.rc == 0) {//更新缓存成功
            } else {
                cleanInput(updateItem, 1);//更新缓存失败，不重新更新缓存
                if (null != data.msg && '' != data.msg && 'undefined' != data.msg) {
                    showMessage(3000, data.msg);
                } else {
                    showMessage(3000, "系统繁忙，更新结算缓存失败，请稍后再试！");
                }
            }
        }
    }, 'json');
}
//清空输入框,并清空缓存
function cleanInput(updateItem, type) {
    switch (updateItem) {
        case 7://优惠码
            $("#couponcode").val("");
            $("#couponcheck").attr("checked", false);
            $("#couponcode").focus();
            $("#couponcode").removeAttr("readonly");
            break;
        case 8://内购
            $('#innerLimitMoney').val("");
            $("#innerLimitcheck").attr("checked", false);
            $("#innerLimitMoney").focus();
            $("#innerLimitMoney").removeAttr("readonly");
            break;
        case 10://乐豆
            $('#useHappyBeanNum').val("");
            $("#happyBeancheck").attr("checked", false);
            $("#useHappyBeanNum").focus();
            $("#useHappyBeanNum").removeAttr("readonly");
            break;
        case 11://SN
            $('#sercicecode').val("");
            $("#sncheck").attr("checked", false);
            $("#sercicecode").focus();
            $("#sercicecode").removeAttr("readonly");
            break;
        default:
    }
    if (type == 2) {
        updateCheckOutCacheNew(updateItem, "");
    }
}
//使用成功弹框提醒
function alertSuccess(updateItem) {
    switch (updateItem) {
        case 7://优惠码
            if ($("#couponcheck").is(":checked")) {
                showMessage(3000, "使用优惠码成功");
            }
            break;
        case 8://内购
            if ($("#innerLimitcheck").is(":checked")) {
                showMessage(3000, "使用内购成功");
            }
            break;
        case 10://乐豆
            if ($("#happyBeancheck").is(":checked")) {
                showMessage(3000, "使用乐豆成功");
            }
            break;
        case 11://SN
            if ($("#sncheck").is(":checked")) {
                showMessage(3000, "使用SN码成功");
            }
            break;
        default:
    }
}
//
function updateAddressCache(id, addresstype) {
    if (addresstype == AddressTypeEnums.SP) {
        updateCheckOutCache(UpdateBackFillItem.INVOICEADDRESS, id);
    } else if (addresstype == AddressTypeEnums.SH || addresstype == AddressTypeEnums.DONGDE) {
        updateCheckOutCache(UpdateBackFillItem.DELIVER, id);
    } else if (addresstype == AddressTypeEnums.HT) {
        updateCheckOutCache(UpdateBackFillItem.CONTRACTADDRESS, id);
    }
}
//收货人地址
function updateConsignee(addresstype) {
    var addressId = getChoseId(addresstype);
    if (addresstype == AddressTypeEnums.DONGDE || addresstype == AddressTypeEnums.SH) {
        updateCheckOutCache(UpdateBackFillItem.DELIVER, addressId);
    } else if (addresstype == AddressTypeEnums.SP) {
        updateCheckOutCache(UpdateBackFillItem.INVOICEADDRESS, addressId);
    }
    else if (addresstype == AddressTypeEnums.HT) {
        updateCheckOutCache(UpdateBackFillItem.CONTRACTADDRESS, addressId);
    }
}
//支付方式
function updatePayType() {
    var paytype = "0";
    paytype = getPayWay();
    if (paytype == undefined) {
        paytype = "0";
    }
    updateCheckOutCache(UpdateBackFillItem.PAYTYPE, paytype);
}

//优惠券
function updateCouponids() {
    var couponids = getCheckedCouponsByArr();
    usevirtualcurrency(UpdateBackFillItem.COUPONIDS, couponids);
}
//获取优惠券ids
function getCheckedCoupons() {
    var couponids = "";
    var ids = [];
    $("#tab_01 .bgses").each(function (i, n) {
        if ($(n).hasClass("pinks")) {
            var id = $(n).attr("id");
            ids.push(id);
        }
    });
    couponids = ids.join(",");
    return couponids;
}
function getCheckedCouponsByArr() {
    var couponids = "";
    var ids = couponidArr;
    couponids = ids.join(",");
    return couponids;
}
//优惠码
function updateCouponCode() {
    var couponcode = $('#couponcode').val();
    usevirtualcurrency(UpdateBackFillItem.COUPONCODE, couponcode);
}
//乐豆
function updateHappyBeanNum() {
    var happybean = $('#useHappyBeanNum').val();
    usevirtualcurrency(UpdateBackFillItem.HAPPYBEAN, happybean);
}
//内购限额
function updateInnerLimitMoney() {
    var innerBuyMoney = $('#innerLimitMoney').val();
    usevirtualcurrency(UpdateBackFillItem.INNERBUYMONEY, innerBuyMoney);
}
//sn
function updateSNCode() {
    var sercicecode = $("#sercicecode").val();
    updateCheckOutCache(UpdateBackFillItem.SN, sercicecode);
}

//数据恢复险
function updatedatarecovery() {
    var insurances = getInsurances();
    usevirtualcurrency(UpdateBackFillItem.DATARECOVERY, insurances);
}
function getInsurances() {
    var insuranceArr = new Array();
    $(".db_back").each(function (i, n) {
        if ($(n).hasClass("db_checked")) {
            var id = $(n).attr("id");
            insuranceArr.push(id.substring(2));
        }
    });
    var insuranceStr = insuranceArr.join(",");
    return insuranceStr;
}
/////////////////////////////////////////////////
//更新缓存--结束
////////////////////////////////////////////////

function checkdata(val, cur) {
    if (getCheckEmpty(val)) {
        return "";
    } else {
        if (getCheckEmpty(cur)) {
            return "";
        } else {
            return cur;
        }
    }
}
/*Returns true if empty*/
function getCheckEmpty(val) {
    if (val == null || val == "" || val == undefined || val == "undefined" || val == "null") {
        return true;
    } else {
        return false;
    }
}
function renderPage(temp, order, updateItem) {
    /*invoiceAddress public*/
    shareInvoiceAddressId = checkdata(order, order.invoiceAddressId);

    type_t = temp.checkoutType;
    buyType = order.buyType;
    if (updateItem != null) {
        alertSuccess(updateItem);
    }
    // showConsign(checkdata(temp, temp.consignee), checkdata(order, order.consigneeId));
    shareConsigneeId = checkdata(order, order.consigneeId);
    if (type_t == "dongdenonumber") {
        showDongdeDirectPage(temp, order);
    } else if (type_t == "dongde") {
        showDongdePage(temp, order);
    } else if (shopId == 9) {
        /*checkdata(temp, temp.scoreApiVo) && temp.scoreApiVo.isCanUseScore == 1*/
        showScorePage(temp, order);
    } else {
        showShopPage(temp, order);
    }
    //使用优惠券成功的提示
    if (temp.successMsg != undefined && temp.successMsg != null && temp.successMsg != "" && temp.successMsg != "success") {
        showMessage(2000, temp.successMsg);
    }

}
function showScorePage(temp, order) {
    /*orderBase.removeContract();
     orderBase.removeInvoice();
     orderBase.removePayType();
     orderDiscount.removeDiscount();
     orderAgree.removeAgree();
     orderNotes.removeNotes();*/
    orderBase.removePayType();//去样式
    showConsignList(checkdata(temp, temp.consignees), checkdata(order, order.consigneeId), AddressTypeEnums.SH);
    showCartList(checkdata(temp, temp.checkOutCart), checkdata(order, order.datarecovery));
    showScores(checkdata(temp, temp.statistics));
    updateConsignee(AddressTypeEnums.SH);
}
function showDongdeDirectPage(temp, order) {
    orderBase.removeContract();
    orderBase.removeInvoice();
    showShopPage(temp, order);
}
function showDongdePage(temp, order) {
    showConsignList(checkdata(temp, temp.consignees), checkdata(order, order.consigneeId), AddressTypeEnums.DONGDE);
    orderBase.removeContract();
    orderBase.removeInvoice();
    orderDiscount.removeDiscount();
    orderNotes.removeNotes();
    agree_conditon();
    showPayType(checkdata(temp, temp.usablePayTypes), checkdata(order, order.paytype),temp);
    showCartList(checkdata(temp, temp.checkOutCart), checkdata(order, order.datarecovery));
    showPrice(checkdata(temp, temp.statistics),temp);
    updateMoreCheckOutCache(checkdata(order, order.invoice), checkdata(order, order.isSendContract));
    if (shopId == 8) {
        invoiceAddressOperate(checkdata(order, order.invoiceIsConsigneeId), checkdata(order, order.invoiceAddressId))
        contractAddressOperate(checkdata(order, order.isSendContract), checkdata(order, order.contractIsConsigneeId), checkdata(order, order.contractAddressId));
    }
}
function showShopPage(temp, order) {
    showConsignList(checkdata(temp, temp.consignees), checkdata(order, order.consigneeId), AddressTypeEnums.SH);
    showInvoice(checkdata(temp, temp.usableInvoices), checkdata(order, order.invoice));
    showHappyBeanWidget(checkdata(temp, temp.leBeanApiVo), checkdata(order, order.happyBeanNum),checkdata(temp, temp.discountsViewInfo));    showInnerBuyWidget(checkdata(temp, temp.innerApiVo), checkdata(order, order.innerBuyMoney));
    showInnerBuyWidget(checkdata(temp, temp.innerApiVo), checkdata(order, order.innerBuyMoney));
    showzc(checkdata(temp, temp.saleTypeSet));
    showsn(checkdata(temp, temp.needSN), checkdata(order, order.servicesn));
    showCouponList(checkdata(temp, temp.couponList), checkdata(order, order.couponids),checkdata(temp, temp.discountsViewInfo));
    showCouponCode(checkdata(order, order.couponcode),checkdata(temp, temp.discountsViewInfo));
    showPayType(checkdata(temp, temp.usablePayTypes), checkdata(order, order.paytype),temp);
    showCartList(checkdata(temp, temp.checkOutCart), checkdata(order, order.datarecovery));
    showPrice(checkdata(temp, temp.statistics),temp);
    updateMoreCheckOutCache(checkdata(order, order.invoice), checkdata(order, order.isSendContract));
    if (shopId == 8) {
        invoiceAddressOperate(checkdata(order, order.invoiceIsConsigneeId), checkdata(order, order.invoiceAddressId))
        contractAddressOperate(checkdata(order, order.isSendContract), checkdata(order, order.contractIsConsigneeId), checkdata(order, order.contractAddressId));
    }
    //changeMoney();
}

function invoiceAddressOperate(invoiceIsConsigneeId, invoiceAddressId) {
    var addresstype = AddressTypeEnums.SP;
    shareInvoiceAddressId = invoiceAddressId;
    if ($(".showbtn-SP").length < 1 || !invoiceIsConsigneeId || invoiceIsConsigneeId == "0") {
        showInvoiceAddress();
    } else if (invoiceIsConsigneeId == "1") {
        // showConsignList("", invoiceAddressId, AddressTypeEnums.SP);
        $("#invoice-cb").prop("checked", true);
        $(".address-" + addresstype).removeClass("pink");
        $("#addressList-" + addresstype).hide();
    }
}
function contractAddressOperate(isSendContract, contractIsConsigneeId, contractAddressId) {
    var addresstype = AddressTypeEnums.HT;
    if (!isSendContract || isSendContract == "0") {
        showConsignList("", "", AddressTypeEnums.HT);
        $("#contract-is").hide();
    } else if (isSendContract == "1") {
        shareContractAddressId = contractAddressId;
        if (!contractIsConsigneeId || contractIsConsigneeId == "0") {
            showContractAddress();
        } else if (contractIsConsigneeId == "1") {
            showConsignList("", shareContractAddressId, addresstype);
            $("#contract-cb").prop("checked", true);
            $(".address-" + addresstype).removeClass("pink");
            $("#addressList-" + addresstype).hide();
        }
        $("#contract-is").show();
        $("#contract-send").prop("checked", true);
    }
}
function agree_conditon() {
    var phone = "";
    try {
        phone = temp.checkOutCart.vendors[0].sorted[0].item.phoneServiceNumber;
    } catch (e) {
        phone = "";
    }
    $("#agree_condition").empty();
    var dongde_agree = ' <span id="dongde_agree" ><input type="checkbox" name="isagreed" id="isagreed" checked="checked" latag="latag_pc_odersubmit_agree"><a target="_blank" href="turnDongde.jhtm?phone=' + phone + '" latag="latag_pc_odersubmit_turnb2c">我同意  《入网协议》</a> </span>';
    $("#agree_condition").html(dongde_agree);
}
//数据恢复险
function title_imgClick(_this) {
    $(_this).parent("b").find(".i_title").toggle();
    $(_this).parent("b").find(".jiao1").toggle();
    $(_this).parent("b").find(".jiao2").toggle();
}
//数据恢复险
function title_imgShow(_this) {
    $(_this).parent("b").find(".i_title").show();
    $(_this).parent("b").find(".jiao1").show();
    $(_this).parent("b").find(".jiao2").show();
}
function title_imgHide(_this) {
    $(_this).parent("b").find(".i_title").hide();
    $(_this).parent("b").find(".jiao1").hide();
    $(_this).parent("b").find(".jiao2").hide();
}
function dataRecoveryClick(_this, id, content) {
    $(_this).parents(".db_back").toggleClass("db_checked");
    if ($(_this).parents(".db_back").hasClass("db_checked")) {
        datarecovery(id, content, 1);
    } else {
        datarecovery(id, content, 0);
    }
}
//提交产品信息
function submitGoods(products_c) {
    var gcodes_in_buy = [];
    for (var i = 0; i < products_c.length; i++) {
        var sortedList = products_c[i].sorted;
        for (var j = 0; j < sortedList.length; j++) {
            gcodes_in_buy.push(sortedList[j].item.id)
        }
    }
    var maingcodes = gcodes_in_buy.join('|');
    _trackData.push(['show', 'checkoutSubmit', 'latag_pc_odersubmit_submit_' + maingcodes]);

}
//提交订单
function submitOrder() {
    try {
        if (products_c != null) {
            submitGoods(products_c);
        }
    } catch (e) {
        console.log(e);
    }
    if (shopId == 8) {

        if (getCheckEmpty($('.jszx_select').val())) {
            showMessage(3000, "请选择或新增发票信息");
            return false;
        }
        if ($('input[name=fpsx]').eq(0).is(':checked') && !$("#jszx_sure_cb").is(":checked")) {
            showMessage(3000, "请确认此订单是代公司采购!");
            return false;
        }
        if (!$("#invoice-cb").is(":checked") && !shareInvoiceAddressId) {
            showMessage(3000, "请选择或新增发票地址");
            return false;
        }
        if ($("#contract-send").is(":checked") && !$("#contract-cb").is(":checked") && !shareContractAddressId) {
            showMessage(3000, "请选择或新增合同地址");
            return false;
        }
    } else if (shopId == 1 || shopId == 2 || shopId == 3) {
        if ($("#invoice_type").html() == "增值发票" && !shareInvoiceAddressId) {
            showMessage(3000, "请选择或新增发票地址");
            return false;
        }
    }

    //协议校验
    var isagreed = $("#isagreed").is(":checked");
    if (!isagreed && shopId != 9) {
        if (type_t == "dongde") {
            showMessage(3000, "请勾选同意 《入网协议》");
        } else {
            if (shopId == 2) {
                showMessage(3000, "请勾选同意《ThinkPad产品网络销售通用条款和条件》 和《电脑喷绘服务条款》");
            } else {
                showMessage(3000, "请勾选同意《联想产品网络销售通用条款和条件》");
            }
        }
        return;
    }
    // 验证服务商品SN码
//    var snCodeList = $("input[id^='sncode_']");
//    if(snCodeList != null && snCodeList.length > 0){
//        var snCheckResult = true;
//        for(var i = 0; i < snCodeList.length; i++){
//            var snCode = snCodeList[i].value;
//            var goodsId = snCodeList[i].id;
//            var material_code = goodsId.split("_")[2];
//            var ajaxdata = {SNCode: snCode, materialCode: material_code};
//            $.ajax({
//                type: "post",
//                url: buy_order.URL.checkServiceSNCode(),
//                async: false,
//                data: ajaxdata,
//                dataType: "json",
//                success: function (data) {
//                    if (data != null) {
//                        if (data.rc == 0) {
//                            snCheckResult = false;
//                        }
//                    }
//                }
//            });
//        }
//        if(!snCheckResult){
//            showMessage(2000, '服务对应的SN码有误');
//            return;
//        }
//    }

    //验证备注
    var remark = $("#ordermark").val();
    //var
    if (null != remark && '' != remark && remark.length > 45) {
        showMessage(3000, '订单备注不能大于45个字符');
        return;
    }
    if (!isEmpty(remark) && !is_forbid(remark)) {
        showMessage(3000, '订单备注含有非法字符');
        return;
    }
    //验证客服经理编码
    var managercode = $("#managercode").val();
    if (null != managercode && '' != managercode && managercode.length > 30) {
        showMessage(3000, '客服经理编码不能大于30个字符');
        return;
    }
    if (!isEmpty(managercode) && !is_forbid(managercode)) {
        showMessage(3000, '客服经理编码含有非法字符');
        return;
    }
    var teltext = $("#pre_phone").val();
    var flag = $("#presellflag").val();
    if((flag == true || flag == "true")&teltext == ""){
        showMessage(3000, '请填写尾款支付联系方式!');
        return;
    }
    if((flag == true || flag == "true") & !check_mobile(teltext)){
        showMessage(3000, '请输入正确尾款联系手机号码!');
        return;
    }
    var tempOldButton = $('#submitbutton').html();
    var tempButton = "<button   style=\"font-size: 18px;cursor: pointer;margin-top: 2px;\">提交中...</button>";
    $('#submitbutton').html(tempButton);
    //预售所留电话

    $.post(buy_order.URL.submitOrder(),
        {
            terminal: terminal,
            orderremark: remark,
            lid: lid,
            cmanagercode: managercode,
            preSaleMobile:teltext
        }, function (data) {
            if (data.rc != 0) {
                if (data.rc == 10014 || data.rc == 20101 || data.rc == 10010) {
                    window.location.href = buy_order.URL.getcart();
                } else {
                    showMessage(3000, data.msg);
                    $('#submitbutton').html(tempOldButton);
                }
                return;
            }
            //成功
            var temp = data.data;
            //调转到支付页面
            window.location.replace(temp);
        }, 'json');
}
$(function () {
    $(".personal_title").click(function () {
        $(this).next().toggle();
        $(this).find("b").toggle();
    });
})
